home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / bin / automake-1.7 < prev    next >
Text File  |  2005-10-16  |  271KB  |  9,445 lines

  1. #!/usr/bin/perl -w
  2. # -*- perl -*-
  3. # Makefile.  Generated from Makefile.in by configure.
  4.  
  5. eval 'case $# in 0) exec /usr/bin/perl -S "$0";; *) exec /usr/bin/perl -S "$0" "$@";; esac'
  6.     if 0;
  7.  
  8. # automake - create Makefile.in from Makefile.am
  9. # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
  10. # Free Software Foundation, Inc.
  11.  
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2, or (at your option)
  15. # any later version.
  16.  
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. # GNU General Public License for more details.
  21.  
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program; if not, write to the Free Software
  24. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  25. # 02111-1307, USA.
  26.  
  27. # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
  28. # Perl reimplementation by Tom Tromey <tromey@redhat.com>.
  29.  
  30. package Language;
  31.  
  32. BEGIN
  33. {
  34.   my $perllibdir = $ENV{'perllibdir'} || '/usr/share/automake-1.7';
  35.   unshift @INC, $perllibdir;
  36.  
  37.   # Override SHELL.  This is required on DJGPP so that system() uses
  38.   # bash, not COMMAND.COM which doesn't quote arguments properly.
  39.   # Other systems aren't expected to use $SHELL when Automake
  40.   # runs, but it should be safe to drop the `if DJGPP' guard if
  41.   # it turns up other systems need the same thing.  After all,
  42.   # if SHELL is used, ./configure's SHELL is always better than
  43.   # the user's SHELL (which may be something like tcsh).
  44.   $ENV{'SHELL'} = '/bin/sh' if exists $ENV{'DJGPP'};
  45. }
  46.  
  47. use Automake::Struct;
  48. struct (# Short name of the language (c, f77...).
  49.         'name' => "\$",
  50.         # Nice name of the language (C, Fortran 77...).
  51.         'Name' => "\$",
  52.  
  53.     # List of configure variables which must be defined.
  54.     'config_vars' => '@',
  55.  
  56.         'ansi'    => "\$",
  57.     # `pure' is `1' or `'.  A `pure' language is one where, if
  58.     # all the files in a directory are of that language, then we
  59.     # do not require the C compiler or any code to call it.
  60.     'pure'   => "\$",
  61.  
  62.     'autodep' => "\$",
  63.  
  64.     # Name of the compiling variable (COMPILE).
  65.         'compiler'  => "\$",
  66.         # Content of the compiling variable.
  67.         'compile'  => "\$",
  68.         # Flag to require compilation without linking (-c).
  69.         'compile_flag' => "\$",
  70.         'extensions' => '@',
  71.     # A subroutine to compute a list of possible extensions of
  72.     # the product given the input extensions.
  73.     # (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo'))
  74.     'output_extensions' => "\$",
  75.     # A list of flag variables used in 'compile'.
  76.     # (defaults to [])
  77.         'flags' => "@",
  78.  
  79.     # The file to use when generating rules for this language.
  80.     # The default is 'depend2'.
  81.     'rule_file' => "\$",
  82.  
  83.         # Name of the linking variable (LINK).
  84.         'linker' => "\$",
  85.         # Content of the linking variable.
  86.         'link' => "\$",
  87.  
  88.         # Name of the linker variable (LD).
  89.         'lder' => "\$",
  90.         # Content of the linker variable ($(CC)).
  91.         'ld' => "\$",
  92.  
  93.         # Flag to specify the output file (-o).
  94.         'output_flag' => "\$",
  95.         '_finish' => "\$",
  96.  
  97.     # This is a subroutine which is called whenever we finally
  98.     # determine the context in which a source file will be
  99.     # compiled.
  100.     '_target_hook' => "\$");
  101.  
  102.  
  103. sub finish ($)
  104. {
  105.   my ($self) = @_;
  106.   if (defined $self->_finish)
  107.     {
  108.       &{$self->_finish} ();
  109.     }
  110. }
  111.  
  112. sub target_hook ($$$$)
  113. {
  114.     my ($self) = @_;
  115.     if (defined $self->_target_hook)
  116.     {
  117.     &{$self->_target_hook} (@_);
  118.     }
  119. }
  120.  
  121. package Automake;
  122.  
  123. use strict 'vars', 'subs';
  124. use Automake::General;
  125. use Automake::XFile;
  126. use Automake::Channels;
  127. use File::Basename;
  128. use Carp;
  129.  
  130. ## ----------- ##
  131. ## Constants.  ##
  132. ## ----------- ##
  133.  
  134. # Parameters set by configure.  Not to be changed.  NOTE: assign
  135. # VERSION as string so that eg version 0.30 will print correctly.
  136. my $VERSION = '1.7.9';
  137. my $PACKAGE = 'automake';
  138. my $libdir = '/usr/share/automake-1.7';
  139.  
  140. # Some regular expressions.  One reason to put them here is that it
  141. # makes indentation work better in Emacs.
  142.  
  143. # Writing singled-quoted-$-terminated regexes is a pain because
  144. # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
  145. # by a closing quote.  Letting perl-mode think the quote is not closed
  146. # leads to all sort of misindentations.  On the other hand, defining
  147. # regexes as double-quoted strings is far less readable.  So usually
  148. # we will write:
  149. #
  150. #  $REGEX = '^regex_value' . "\$";
  151.  
  152. my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
  153. my $WHITE_PATTERN = '^\s*' . "\$";
  154. my $COMMENT_PATTERN = '^#';
  155. my $TARGET_PATTERN='[$a-zA-Z_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
  156. # A rule has three parts: a list of targets, a list of dependencies,
  157. # and optionally actions.
  158. my $RULE_PATTERN =
  159.   "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
  160.  
  161. my $SUFFIX_RULE_PATTERN =
  162.     '^(\.[a-zA-Z0-9_(){}$+@]+)(\.[a-zA-Z0-9_(){}$+@]+)' . "\$";
  163. # Only recognize leading spaces, not leading tabs.  If we recognize
  164. # leading tabs here then we need to make the reader smarter, because
  165. # otherwise it will think rules like `foo=bar; \' are errors.
  166. my $MACRO_PATTERN = '^[.A-Za-z0-9_@]+' . "\$";
  167. my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
  168. # This pattern recognizes a Gnits version id and sets $1 if the
  169. # release is an alpha release.  We also allow a suffix which can be
  170. # used to extend the version number with a "fork" identifier.
  171. my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
  172.  
  173. my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
  174. my $ELSE_PATTERN =
  175.   '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
  176. my $ENDIF_PATTERN =
  177.   '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
  178. my $PATH_PATTERN = '(\w|[/.-])+';
  179. # This will pass through anything not of the prescribed form.
  180. my $INCLUDE_PATTERN = ('^include\s+'
  181.                . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
  182.                . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
  183.                . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
  184.  
  185. # This handles substitution references like ${foo:.a=.b}.
  186. my $SUBST_REF_PATTERN = "^([^:]*):([^=]*)=(.*)\$";
  187.  
  188. # Match `-d' as a command-line argument in a string.
  189. my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
  190. # Directories installed during 'install-exec' phase.
  191. my $EXEC_DIR_PATTERN =
  192.   '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
  193.  
  194. # Constants to define the "strictness" level.
  195. use constant FOREIGN => 0;
  196. use constant GNU     => 1;
  197. use constant GNITS   => 2;
  198.  
  199. # Values for AC_CANONICAL_*
  200. use constant AC_CANONICAL_HOST   => 1;
  201. use constant AC_CANONICAL_SYSTEM => 2;
  202.  
  203. # Values indicating when something should be cleaned.
  204. use constant MOSTLY_CLEAN     => 0;
  205. use constant CLEAN            => 1;
  206. use constant DIST_CLEAN       => 2;
  207. use constant MAINTAINER_CLEAN => 3;
  208.  
  209. # Libtool files.
  210. my @libtool_files = qw(ltmain.sh config.guess config.sub);
  211. # ltconfig appears here for compatibility with old versions of libtool.
  212. my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
  213.  
  214. # Commonly found files we look for and automatically include in
  215. # DISTFILES.
  216. my @common_files =
  217.     (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
  218.     COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO acinclude.m4
  219.     ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
  220.     configure configure.ac configure.in depcomp elisp-comp
  221.     install-sh libversion.in mdate-sh missing mkinstalldirs
  222.     py-compile texinfo.tex ylwrap),
  223.      @libtool_files, @libtool_sometimes);
  224.  
  225. # Commonly used files we auto-include, but only sometimes.
  226. my @common_sometimes =
  227.     qw(aclocal.m4 acconfig.h config.h.top config.h.bot stamp-vti);
  228.  
  229. # Standard directories from the GNU Coding Standards, and additional
  230. # pkg* directories from Automake.  Stored in a hash for fast member check.
  231. my %standard_prefix =
  232.     map { $_ => 1 } (qw(bin data exec include info lib libexec lisp
  233.             localstate man man1 man2 man3 man4 man5 man6
  234.             man7 man8 man9 oldinclude pkgdatadir
  235.             pkgincludedir pkglibdir sbin sharedstate
  236.             sysconf));
  237.  
  238. # Declare the macros that define known variables, so we can
  239. # hint the user if she try to use one of these variables.
  240.  
  241. # Macros accessible via aclocal.
  242. my %am_macro_for_var =
  243.   (
  244.    ANSI2KNR => 'AM_C_PROTOTYPES',
  245.    CCAS => 'AM_PROG_AS',
  246.    CCASFLAGS => 'AM_PROG_AS',
  247.    EMACS => 'AM_PATH_LISPDIR',
  248.    GCJ => 'AM_PROG_GCJ',
  249.    LEX => 'AM_PROG_LEX',
  250.    LIBTOOL => 'AC_PROG_LIBTOOL',
  251.    lispdir => 'AM_PATH_LISPDIR',
  252.    pkgpyexecdir => 'AM_PATH_PYTHON',
  253.    pkgpythondir => 'AM_PATH_PYTHON',
  254.    pyexecdir => 'AM_PATH_PYTHON',
  255.    PYTHON => 'AM_PATH_PYTHON',
  256.    pythondir => 'AM_PATH_PYTHON',
  257.    U => 'AM_C_PROTOTYPES',
  258.    );
  259.  
  260. # Macros shipped with Autoconf.
  261. my %ac_macro_for_var =
  262.   (
  263.    CC => 'AC_PROG_CC',
  264.    CFLAGS => 'AC_PROG_CC',
  265.    CXX => 'AC_PROG_CXX',
  266.    CXXFLAGS => 'AC_PROG_CXX',
  267.    F77 => 'AC_PROG_F77',
  268.    F77FLAGS => 'AC_PROG_F77',
  269.    RANLIB => 'AC_PROG_RANLIB',
  270.    YACC => 'AC_PROG_YACC',
  271.    );
  272.  
  273. # Copyright on generated Makefile.ins.
  274. my $gen_copyright = "\
  275. # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
  276. # Free Software Foundation, Inc.
  277. # This Makefile.in is free software; the Free Software Foundation
  278. # gives unlimited permission to copy and/or distribute it,
  279. # with or without modifications, as long as this notice is preserved.
  280.  
  281. # This program is distributed in the hope that it will be useful,
  282. # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  283. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  284. # PARTICULAR PURPOSE.
  285. ";
  286.  
  287. # These constants are returned by lang_*_rewrite functions.
  288. # LANG_SUBDIR means that the resulting object file should be in a
  289. # subdir if the source file is.  In this case the file name cannot
  290. # have `..' components.
  291. use constant LANG_IGNORE  => 0;
  292. use constant LANG_PROCESS => 1;
  293. use constant LANG_SUBDIR  => 2;
  294.  
  295. # These are used when keeping track of whether an object can be built
  296. # by two different paths.
  297. use constant COMPILE_LIBTOOL  => 1;
  298. use constant COMPILE_ORDINARY => 2;
  299.  
  300.  
  301.  
  302. ## ---------------------------------- ##
  303. ## Variables related to the options.  ##
  304. ## ---------------------------------- ##
  305.  
  306. # TRUE if we should always generate Makefile.in.
  307. my $force_generation = 1;
  308.  
  309. # Strictness level as set on command line.
  310. my $default_strictness = GNU;
  311.  
  312. # Name of strictness level, as set on command line.
  313. my $default_strictness_name = 'gnu';
  314.  
  315. # This is TRUE if automatic dependency generation code should be
  316. # included in generated Makefile.in.
  317. my $cmdline_use_dependencies = 1;
  318.  
  319. # From the Perl manual.
  320. my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
  321.  
  322. # TRUE if missing standard files should be installed.
  323. my $add_missing = 0;
  324.  
  325. # TRUE if we should copy missing files; otherwise symlink if possible.
  326. my $copy_missing = 0;
  327.  
  328. # TRUE if we should always update files that we know about.
  329. my $force_missing = 0;
  330.  
  331.  
  332. ## ---------------------------------------- ##
  333. ## Variables filled during files scanning.  ##
  334. ## ---------------------------------------- ##
  335.  
  336. # Name of the top autoconf input: `configure.ac' or `configure.in'.
  337. my $configure_ac = '';
  338.  
  339. # Files found by scanning configure.ac for LIBOBJS.
  340. my %libsources = ();
  341.  
  342. # Names used in AC_CONFIG_HEADER call.
  343. my @config_headers = ();
  344. # Where AC_CONFIG_HEADER appears.
  345. my $config_header_location;
  346.  
  347. # Directory where output files go.  Actually, output files are
  348. # relative to this directory.
  349. my $output_directory;
  350.  
  351. # List of Makefile.am's to process, and their corresponding outputs.
  352. my @input_files = ();
  353. my %output_files = ();
  354.  
  355. # Complete list of Makefile.am's that exist.
  356. my @configure_input_files = ();
  357.  
  358. # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
  359. # and their outputs.
  360. my @other_input_files = ();
  361. # Where the last AC_CONFIG_FILES/AC_OUTPUT appears.
  362. my $ac_config_files_location;
  363.  
  364. # List of directories to search for configure-required files.  This
  365. # can be set by AC_CONFIG_AUX_DIR.
  366. my @config_aux_path = qw(. .. ../..);
  367. my $config_aux_dir = '';
  368. my $config_aux_dir_set_in_configure_in = 0;
  369.  
  370. # Whether AM_GNU_GETTEXT has been seen in configure.ac.
  371. my $seen_gettext = 0;
  372. # Whether AM_GNU_GETTEXT([external]) is used.
  373. my $seen_gettext_external = 0;
  374. # Where AM_GNU_GETTEXT appears.
  375. my $ac_gettext_location;
  376.  
  377. # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).
  378. my $seen_canonical = 0;
  379. my $canonical_location;
  380.  
  381. # Where AM_MAINTAINER_MODE appears.
  382. my $seen_maint_mode;
  383.  
  384. # Actual version we've seen.
  385. my $package_version = '';
  386.  
  387. # Where version is defined.
  388. my $package_version_location;
  389.  
  390. # TRUE if we've seen AC_ENABLE_MULTILIB.
  391. my $seen_multilib = 0;
  392.  
  393. # TRUE if we've seen AM_PROG_CC_C_O
  394. my $seen_cc_c_o = 0;
  395.  
  396. # Where AM_INIT_AUTOMAKE is called;
  397. my $seen_init_automake = 0;
  398.  
  399. # TRUE if we've seen AM_AUTOMAKE_VERSION.
  400. my $seen_automake_version = 0;
  401.  
  402. # Hash table of discovered configure substitutions.  Keys are names,
  403. # values are `FILE:LINE' strings which are used by error message
  404. # generation.
  405. my %configure_vars = ();
  406.  
  407. # This is used to keep track of which variable definitions we are
  408. # scanning.  It is only used in certain limited ways, but it has to be
  409. # global.  It is declared just for documentation purposes.
  410. my %vars_scanned = ();
  411.  
  412. # TRUE if --cygnus seen.
  413. my $cygnus_mode = 0;
  414.  
  415. # Hash table of AM_CONDITIONAL variables seen in configure.
  416. my %configure_cond = ();
  417.  
  418. # This maps extensions onto language names.
  419. my %extension_map = ();
  420.  
  421. # List of the DIST_COMMON files we discovered while reading
  422. # configure.in
  423. my $configure_dist_common = '';
  424.  
  425. # This maps languages names onto objects.
  426. my %languages = ();
  427.  
  428. # List of targets we must always output.
  429. # FIXME: Complete, and remove falsely required targets.
  430. my %required_targets =
  431.   (
  432.    'all'          => 1,
  433.    'dvi'      => 1,
  434.    'pdf'      => 1,
  435.    'ps'          => 1,
  436.    'info'      => 1,
  437.    'install-info' => 1,
  438.    'install'      => 1,
  439.    'install-data' => 1,
  440.    'install-exec' => 1,
  441.    'uninstall'    => 1,
  442.  
  443.    # FIXME: Not required, temporary hacks.
  444.    # Well, actually they are sort of required: the -recursive
  445.    # targets will run them anyway...
  446.    'dvi-am'          => 1,
  447.    'pdf-am'          => 1,
  448.    'ps-am'           => 1,
  449.    'info-am'         => 1,
  450.    'install-data-am' => 1,
  451.    'install-exec-am' => 1,
  452.    'installcheck-am' => 1,
  453.    'uninstall-am' => 1,
  454.  
  455.    'install-man' => 1,
  456.   );
  457.  
  458. # This is set to 1 when Automake needs to be run again.
  459. # (For instance, this happens when an auxiliary file such as
  460. # depcomp is added after the toplevel Makefile.in -- which
  461. # should distribute depcomp -- has been generated.)
  462. my $automake_needs_to_reprocess_all_files = 0;
  463.  
  464. # Options set via AM_INIT_AUTOMAKE.
  465. my $global_options = '';
  466.  
  467. # Same as $suffix_rules (declared below), but records only the
  468. # default rules supplied by the languages Automake supports.
  469. my $suffix_rules_default;
  470.  
  471. # If a file name appears as a key in this hash, then it has already
  472. # been checked for.  This variable is local to the "require file"
  473. # functions.
  474. my %require_file_found = ();
  475.  
  476.  
  477. ################################################################
  478.  
  479. ## ------------------------------------------ ##
  480. ## Variables reset by &initialize_per_input.  ##
  481. ## ------------------------------------------ ##
  482.  
  483. # Basename and relative dir of the input file.
  484. my $am_file_name;
  485. my $am_relative_dir;
  486.  
  487. # Same but wrt Makefile.in.
  488. my $in_file_name;
  489. my $relative_dir;
  490.  
  491. # These two variables are used when generating each Makefile.in.
  492. # They hold the Makefile.in until it is ready to be printed.
  493. my $output_rules;
  494. my $output_vars;
  495. my $output_trailer;
  496. my $output_all;
  497. my $output_header;
  498.  
  499. # Suffixes found during a run.
  500. my @suffixes;
  501.  
  502. # Handling the variables.
  503. #
  504. # For a $VAR:
  505. # - $var_value{$VAR}{$COND} is its value associated to $COND,
  506. # - $var_location{$VAR}{$COND} is where it was defined,
  507. # - $var_comment{$VAR}{$COND} are the comments associated to it.
  508. # - $var_type{$VAR}{$COND} is how it has been defined (`', `+', or `:'),
  509. # - $var_owner{$VAR}{$COND} tells who owns the variable (VAR_AUTOMAKE,
  510. #     VAR_CONFIGURE, or VAR_MAKEFILE).
  511. my %var_value;
  512. my %var_location;
  513. my %var_comment;
  514. my %var_type;
  515. my %var_owner;
  516. # Possible values for var_owner.  Defined so that the owner of
  517. # a variable can only be increased (e.g Automake should not
  518. # override a configure or Makefile variable).
  519. use constant VAR_AUTOMAKE => 0; # Variable defined by Automake.
  520. use constant VAR_CONFIGURE => 1;# Variable defined in configure.ac.
  521. use constant VAR_MAKEFILE => 2; # Variable defined in Makefile.am.
  522.  
  523. # This holds a 1 if a particular variable was examined.
  524. my %content_seen;
  525.  
  526. # This holds the names which are targets.  These also appear in
  527. # %contents.  $targets{TARGET}{COND} is the location of the definition
  528. # of TARGET for condition COND.  TARGETs should not include
  529. # a trailing $(EXEEXT), we record this in %target_name.
  530. my %targets;
  531.  
  532. # $target_source{TARGET}{COND} is the filename where TARGET
  533. # were defined for condition COND.  Note this must be a
  534. # filename, *without* any line number.
  535. my %target_source;
  536.  
  537. # $target_name{TARGET}{COND} is the real name of TARGET (in condition COND).
  538. # The real name is often TARGET or TARGET$(EXEEXT), and TARGET never
  539. # contain $(EXEEXT)
  540. my %target_name;
  541.  
  542. # $target_owner{TARGET}{COND} the owner of TARGET in condition COND.
  543. my %target_owner;
  544. use constant TARGET_AUTOMAKE => 0; # Target defined by Automake.
  545. use constant TARGET_USER => 1;    # Target defined in the user's Makefile.am.
  546.  
  547. # This is the conditional stack.
  548. my @cond_stack;
  549.  
  550. # This holds the set of included files.
  551. my @include_stack;
  552.  
  553. # This holds a list of directories which we must create at `dist'
  554. # time.  This is used in some strange scenarios involving weird
  555. # AC_OUTPUT commands.
  556. my %dist_dirs;
  557.  
  558. # List of dependencies for the obvious targets.
  559. my @all;
  560. my @check;
  561. my @check_tests;
  562.  
  563. # Holds the dependencies of targets which dependencies are factored.
  564. # Typically, `.PHONY' will appear in plenty of *.am files, but must
  565. # be output once.  Arguably all pure dependencies could be subject
  566. # to this factorization, but it is not unpleasant to have paragraphs
  567. # in Makefile: keeping related stuff altogether.
  568. my %dependencies;
  569.  
  570. # Holds the factored actions.  Tied to %DEPENDENCIES, i.e., filled
  571. # only when keys exists in %DEPENDENCIES.
  572. my %actions;
  573.  
  574. # Keys in this hash table are files to delete.  The associated
  575. # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
  576. my %clean_files;
  577.  
  578. # Keys in this hash table are object files or other files in
  579. # subdirectories which need to be removed.  This only holds files
  580. # which are created by compilations.  The value in the hash indicates
  581. # when the file should be removed.
  582. my %compile_clean_files;
  583.  
  584. # Keys in this hash table are directories where we expect to build a
  585. # libtool object.  We use this information to decide what directories
  586. # to delete.
  587. my %libtool_clean_directories;
  588.  
  589. # Value of `$(SOURCES)', used by tags.am.
  590. my @sources;
  591. # Sources which go in the distribution.
  592. my @dist_sources;
  593.  
  594. # This hash maps object file names onto their corresponding source
  595. # file names.  This is used to ensure that each object is created
  596. # by a single source file.
  597. my %object_map;
  598.  
  599. # This hash maps object file names onto an integer value representing
  600. # whether this object has been built via ordinary compilation or
  601. # libtool compilation (the COMPILE_* constants).
  602. my %object_compilation_map;
  603.  
  604.  
  605. # This keeps track of the directories for which we've already
  606. # created dirstamp code.
  607. my %directory_map;
  608.  
  609. # All .P files.
  610. my %dep_files;
  611.  
  612. # Strictness levels.
  613. my $strictness;
  614. my $strictness_name;
  615.  
  616. # Options from AUTOMAKE_OPTIONS.
  617. my %options;
  618.  
  619. # Whether or not dependencies are handled.  Can be further changed
  620. # in handle_options.
  621. my $use_dependencies;
  622.  
  623. # This is a list of all targets to run during "make dist".
  624. my @dist_targets;
  625.  
  626. # Keys in this hash are the basenames of files which must depend on
  627. # ansi2knr.  Values are either the empty string, or the directory in
  628. # which the ANSI source file appears; the directory must have a
  629. # trailing `/'.
  630. my %de_ansi_files;
  631.  
  632. # This maps the source extension for all suffix rule seen to
  633. # a \hash whose keys are the possible output extensions.
  634. #
  635. # Note that this is transitively closed by construction:
  636. # if we have
  637. #       exists $suffix_rules{$ext1}{$ext2}
  638. #    && exists $suffix_rules{$ext2}{$ext3}
  639. # then we also have
  640. #       exists $suffix_rules{$ext1}{$ext3}
  641. #
  642. # So it's easy to check whether '.foo' can be transformed to '.$(OBJEXT)'
  643. # by checking whether $suffix_rules{'.foo'}{'.$(OBJEXT)'} exist.  This
  644. # will work even if transforming '.foo' to '.$(OBJEXT)' involves a chain
  645. # of several suffix rules.
  646. #
  647. # The value of `$suffix_rules{$ext1}{$ext2}' is the a pair
  648. # `[ $next_sfx, $dist ]' where `$next_sfx' is target suffix
  649. # for the next rule to use to reach '$ext2', and `$dist' the
  650. # distance to `$ext2'.
  651. my $suffix_rules;
  652.  
  653. # This is the name of the redirect `all' target to use.
  654. my $all_target;
  655.  
  656. # This keeps track of which extensions we've seen (that we care
  657. # about).
  658. my %extension_seen;
  659.  
  660. # This is random scratch space for the language finish functions.
  661. # Don't randomly overwrite it; examine other uses of keys first.
  662. my %language_scratch;
  663.  
  664. # We keep track of which objects need special (per-executable)
  665. # handling on a per-language basis.
  666. my %lang_specific_files;
  667.  
  668. # This is set when `handle_dist' has finished.  Once this happens,
  669. # we should no longer push on dist_common.
  670. my $handle_dist_run;
  671.  
  672. # Used to store a set of linkers needed to generate the sources currently
  673. # under consideration.
  674. my %linkers_used;
  675.  
  676. # True if we need `LINK' defined.  This is a hack.
  677. my $need_link;
  678.  
  679. # This is the list of such variables to output.
  680. # FIXME: Might be useless actually.
  681. my @var_list;
  682.  
  683. # Was get_object_extension run?
  684. # FIXME: This is a hack. a better switch should be found.
  685. my $get_object_extension_was_run;
  686.  
  687. # Contains a stack of `from' parts of variable substitutions currently in
  688. # force.
  689. my @substfroms;
  690.  
  691. # Contains a stack of `to' parts of variable substitutions currently in
  692. # force.
  693. my @substtos;
  694.  
  695. # This keeps track of all variables defined by subobjname.
  696. # The value stored is the variable names.
  697. # The key has the form "(COND1)VAL1(COND2)VAL2..." where VAL1 and VAL2
  698. # are the values of the variable for condition COND1 and COND2.
  699. my %subobjvar = ();
  700.  
  701. # This hash records helper variables used to implement '+=' in conditionals.
  702. # Keys have the form "VAR:CONDITIONS".  The value associated to a key is
  703. # the named of the helper variable used to append to VAR in CONDITIONS.
  704. my %appendvar = ();
  705.  
  706.  
  707. ## --------------------------------- ##
  708. ## Forward subroutine declarations.  ##
  709. ## --------------------------------- ##
  710. sub register_language (%);
  711. sub file_contents_internal ($$%);
  712. sub define_objects_from_sources ($$$$$$$);
  713.  
  714.  
  715. # &initialize_per_input ()
  716. # ------------------------
  717. # (Re)-Initialize per-Makefile.am variables.
  718. sub initialize_per_input ()
  719. {
  720.     reset_local_duplicates ();
  721.  
  722.     $am_file_name = '';
  723.     $am_relative_dir = '';
  724.  
  725.     $in_file_name = '';
  726.     $relative_dir = '';
  727.  
  728.     $output_rules = '';
  729.     $output_vars = '';
  730.     $output_trailer = '';
  731.     $output_all = '';
  732.     $output_header = '';
  733.  
  734.     @suffixes = ();
  735.  
  736.     %var_value = ();
  737.     %var_location = ();
  738.     %var_comment = ();
  739.     %var_type = ();
  740.     %var_owner = ();
  741.  
  742.     %content_seen = ();
  743.  
  744.     %targets = ();
  745.     %target_source = ();
  746.     %target_name = ();
  747.     %target_owner = ();
  748.  
  749.     @cond_stack = ();
  750.  
  751.     @include_stack = ();
  752.  
  753.     %dist_dirs = ();
  754.  
  755.     @all = ();
  756.     @check = ();
  757.     @check_tests = ();
  758.  
  759.     %dependencies =
  760.       (
  761.        # Texinfoing.
  762.        'dvi'      => [],
  763.        'dvi-am'   => [],
  764.        'pdf'      => [],
  765.        'pdf-am'   => [],
  766.        'ps'       => [],
  767.        'ps-am'    => [],
  768.        'info'     => [],
  769.        'info-am'  => [],
  770.  
  771.        # Installing/uninstalling.
  772.        'install-data-am'      => [],
  773.        'install-exec-am'      => [],
  774.        'uninstall-am'         => [],
  775.  
  776.        'install-man'          => [],
  777.        'uninstall-man'          => [],
  778.  
  779.        'install-info'         => [],
  780.        'install-info-am'      => [],
  781.        'uninstall-info'       => [],
  782.  
  783.        'installcheck-am'      => [],
  784.  
  785.        # Cleaning.
  786.        'clean-am'             => [],
  787.        'mostlyclean-am'       => [],
  788.        'maintainer-clean-am'  => [],
  789.        'distclean-am'         => [],
  790.        'clean'                => [],
  791.        'mostlyclean'          => [],
  792.        'maintainer-clean'     => [],
  793.        'distclean'            => [],
  794.  
  795.        # Tarballing.
  796.        'dist-all'             => [],
  797.  
  798.        # Phoning.
  799.        '.PHONY'               => []
  800.       );
  801.     %actions = ();
  802.  
  803.     %clean_files = ();
  804.  
  805.     @sources = ();
  806.     @dist_sources = ();
  807.  
  808.     %object_map = ();
  809.     %object_compilation_map = ();
  810.  
  811.     %directory_map = ();
  812.  
  813.     %dep_files = ();
  814.  
  815.     $strictness = $default_strictness;
  816.     $strictness_name = $default_strictness_name;
  817.  
  818.     %options = ();
  819.  
  820.     $use_dependencies = $cmdline_use_dependencies;
  821.  
  822.     @dist_targets = ();
  823.  
  824.     %de_ansi_files = ();
  825.  
  826.  
  827.     # The first time we initialize the variables,
  828.     # we save the value of $suffix_rules.
  829.     if (defined $suffix_rules_default)
  830.       {
  831.     $suffix_rules = $suffix_rules_default;
  832.       }
  833.     else
  834.       {
  835.     $suffix_rules_default = $suffix_rules;
  836.       }
  837.  
  838.     $all_target = '';
  839.  
  840.     %extension_seen = ();
  841.  
  842.     %language_scratch = ();
  843.  
  844.     %lang_specific_files = ();
  845.  
  846.     $handle_dist_run = 0;
  847.  
  848.     $need_link = 0;
  849.  
  850.     @var_list = ();
  851.  
  852.     $get_object_extension_was_run = 0;
  853.  
  854.     %compile_clean_files = ();
  855.  
  856.     # We always include `.'.  This isn't strictly correct.
  857.     %libtool_clean_directories = ('.' => 1);
  858.  
  859.     %subobjvar = ();
  860.  
  861.     %appendvar = ();
  862. }
  863.  
  864.  
  865. ################################################################
  866.  
  867. # Initialize our list of error/warning channels.
  868. # Do not forget to update &usage and the manual
  869. # if you add or change a warning channel.
  870.  
  871. # Fatal errors.
  872. register_channel 'fatal', type => 'fatal';
  873. # Common errors.
  874. register_channel 'error', type => 'error';
  875. # Errors related to GNU Standards.
  876. register_channel 'error-gnu', type => 'error';
  877. # Errors related to GNU Standards that should be warnings in `foreign' mode.
  878. register_channel 'error-gnu/warn', type => 'error';
  879. # Errors related to GNITS Standards (silent by default).
  880. register_channel 'error-gnits', type => 'error', silent => 1;
  881. # Internal errors.
  882. register_channel 'automake', type => 'fatal', backtrace => 1,
  883.   header => ("####################\n" .
  884.          "## Internal Error ##\n" .
  885.          "####################\n"),
  886.   footer => "\nPlease contact <bug-automake\@gnu.org>.";
  887.  
  888. # Warnings related to GNU Coding Standards.
  889. register_channel 'gnu', type => 'warning';
  890. # Warnings about obsolete features (silent by default).
  891. register_channel 'obsolete', type => 'warning', silent => 1;
  892. # Warnings about non-portable constructs.
  893. register_channel 'portability', type => 'warning', silent => 1;
  894. # Weird syntax, unused variables, typos...
  895. register_channel 'syntax', type => 'warning';
  896. # Warnings about unsupported (or mis-supported) features.
  897. register_channel 'unsupported', type => 'warning';
  898.  
  899. # For &verb.
  900. register_channel 'verb', type => 'debug', silent => 1;
  901. # Informative messages.
  902. register_channel 'note', type => 'debug', silent => 0;
  903.  
  904.  
  905. # Initialize our list of languages that are internally supported.
  906.  
  907. # C.
  908. register_language ('name' => 'c',
  909.            'Name' => 'C',
  910.            'config_vars' => ['CC'],
  911.            'ansi' => 1,
  912.            'autodep' => '',
  913.            'flags' => ['CFLAGS', 'CPPFLAGS'],
  914.            'compiler' => 'COMPILE',
  915.            'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
  916.            'lder' => 'CCLD',
  917.            'ld' => '$(CC)',
  918.            'linker' => 'LINK',
  919.            'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  920.            'compile_flag' => '-c',
  921.            'extensions' => ['.c'],
  922.            '_finish' => \&lang_c_finish);
  923.  
  924. # C++.
  925. register_language ('name' => 'cxx',
  926.            'Name' => 'C++',
  927.            'config_vars' => ['CXX'],
  928.            'linker' => 'CXXLINK',
  929.            'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  930.            'autodep' => 'CXX',
  931.            'flags' => ['CXXFLAGS', 'CPPFLAGS'],
  932.            'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
  933.            'compiler' => 'CXXCOMPILE',
  934.            'compile_flag' => '-c',
  935.            'output_flag' => '-o',
  936.            'lder' => 'CXXLD',
  937.            'ld' => '$(CXX)',
  938.            'pure' => 1,
  939.            'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
  940.  
  941. # Objective C.
  942. register_language ('name' => 'objc',
  943.            'Name' => 'Objective C',
  944.            'config_vars' => ['OBJC'],
  945.            'linker' => 'OBJCLINK',,
  946.             'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  947.            'autodep' => 'OBJC',
  948.            'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
  949.            'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
  950.            'compiler' => 'OBJCCOMPILE',
  951.            'compile_flag' => '-c',
  952.            'output_flag' => '-o',
  953.            'lder' => 'OBJCLD',
  954.            'ld' => '$(OBJC)',
  955.            'pure' => 1,
  956.            'extensions' => ['.m']);
  957.  
  958. # Headers.
  959. register_language ('name' => 'header',
  960.            'Name' => 'Header',
  961.            'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
  962.                     '.hpp', '.inc'],
  963.            # No output.
  964.            'output_extensions' => sub { return () },
  965.            # Nothing to do.
  966.            '_finish' => sub { });
  967.  
  968. # Yacc (C & C++).
  969. register_language ('name' => 'yacc',
  970.            'Name' => 'Yacc',
  971.            'config_vars' => ['YACC'],
  972.            'flags' => ['YFLAGS'],
  973.            'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
  974.            'compiler' => 'YACCCOMPILE',
  975.            'extensions' => ['.y'],
  976.            'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
  977.                         return ($ext,) },
  978.            'rule_file' => 'yacc',
  979.            '_finish' => \&lang_yacc_finish,
  980.            '_target_hook' => \&lang_yacc_target_hook);
  981. register_language ('name' => 'yaccxx',
  982.            'Name' => 'Yacc (C++)',
  983.            'config_vars' => ['YACC'],
  984.            'rule_file' => 'yacc',
  985.            'flags' => ['YFLAGS'],
  986.            'compiler' => 'YACCCOMPILE',
  987.            'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
  988.            'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
  989.            'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
  990.                         return ($ext,) },
  991.            '_finish' => \&lang_yacc_finish,
  992.            '_target_hook' => \&lang_yacc_target_hook);
  993.  
  994. # Lex (C & C++).
  995. register_language ('name' => 'lex',
  996.            'Name' => 'Lex',
  997.            'config_vars' => ['LEX'],
  998.            'rule_file' => 'lex',
  999.            'flags' => ['LFLAGS'],
  1000.            'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
  1001.            'compiler' => 'LEXCOMPILE',
  1002.            'extensions' => ['.l'],
  1003.            'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
  1004.                         return ($ext,) },
  1005.            '_finish' => \&lang_lex_finish,
  1006.            '_target_hook' => \&lang_lex_target_hook);
  1007. register_language ('name' => 'lexxx',
  1008.            'Name' => 'Lex (C++)',
  1009.            'config_vars' => ['LEX'],
  1010.            'rule_file' => 'lex',
  1011.            'flags' => ['LFLAGS'],
  1012.            'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
  1013.            'compiler' => 'LEXCOMPILE',
  1014.            'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
  1015.            'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
  1016.                         return ($ext,) },
  1017.            '_finish' => \&lang_lex_finish,
  1018.            '_target_hook' => \&lang_lex_target_hook);
  1019.  
  1020. # Assembler.
  1021. register_language ('name' => 'asm',
  1022.            'Name' => 'Assembler',
  1023.            'config_vars' => ['CCAS', 'CCASFLAGS'],
  1024.  
  1025.            'flags' => ['CCASFLAGS'],
  1026.            # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
  1027.            # or anything else required.  They can also set AS.
  1028.            'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
  1029.            'compiler' => 'CCASCOMPILE',
  1030.            'compile_flag' => '-c',
  1031.            'extensions' => ['.s', '.S'],
  1032.  
  1033.            # With assembly we still use the C linker.
  1034.            '_finish' => \&lang_c_finish);
  1035.  
  1036. # Fortran 77
  1037. register_language ('name' => 'f77',
  1038.            'Name' => 'Fortran 77',
  1039.            'linker' => 'F77LINK',
  1040.            'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  1041.            'flags' => ['FFLAGS'],
  1042.            'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
  1043.            'compiler' => 'F77COMPILE',
  1044.            'compile_flag' => '-c',
  1045.            'output_flag' => '-o',
  1046.            'lder' => 'F77LD',
  1047.            'ld' => '$(F77)',
  1048.            'pure' => 1,
  1049.            'extensions' => ['.f', '.for', '.f90']);
  1050.  
  1051. # Preprocessed Fortran 77
  1052. #
  1053. # The current support for preprocessing Fortran 77 just involves
  1054. # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
  1055. # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
  1056. # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
  1057. # for `make' Version 3.76 Beta' (specifically, from info file
  1058. # `(make)Catalogue of Rules').
  1059. #
  1060. # A better approach would be to write an Autoconf test
  1061. # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
  1062. # Fortran 77 compilers know how to do preprocessing.  The Autoconf
  1063. # macro AC_PROG_FPP should test the Fortran 77 compiler first for
  1064. # preprocessing capabilities, and then fall back on cpp (if cpp were
  1065. # available).
  1066. register_language ('name' => 'ppf77',
  1067.            'Name' => 'Preprocessed Fortran 77',
  1068.            'config_vars' => ['F77'],
  1069.            'linker' => 'F77LINK',
  1070.            'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  1071.            'lder' => 'F77LD',
  1072.            'ld' => '$(F77)',
  1073.            'flags' => ['FFLAGS', 'CPPFLAGS'],
  1074.            'compiler' => 'PPF77COMPILE',
  1075.            'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
  1076.            'compile_flag' => '-c',
  1077.            'output_flag' => '-o',
  1078.            'pure' => 1,
  1079.            'extensions' => ['.F']);
  1080.  
  1081. # Ratfor.
  1082. register_language ('name' => 'ratfor',
  1083.            'Name' => 'Ratfor',
  1084.            'config_vars' => ['F77'],
  1085.            'linker' => 'F77LINK',
  1086.            'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  1087.            'lder' => 'F77LD',
  1088.            'ld' => '$(F77)',
  1089.            'flags' => ['RFLAGS', 'FFLAGS'],
  1090.            # FIXME also FFLAGS.
  1091.            'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
  1092.            'compiler' => 'RCOMPILE',
  1093.            'compile_flag' => '-c',
  1094.            'output_flag' => '-o',
  1095.            'pure' => 1,
  1096.            'extensions' => ['.r']);
  1097.  
  1098. # Java via gcj.
  1099. register_language ('name' => 'java',
  1100.            'Name' => 'Java',
  1101.            'config_vars' => ['GCJ'],
  1102.            'linker' => 'GCJLINK',
  1103.            'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  1104.            'autodep' => 'GCJ',
  1105.            'flags' => ['GCJFLAGS'],
  1106.            'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
  1107.            'compiler' => 'GCJCOMPILE',
  1108.            'compile_flag' => '-c',
  1109.            'output_flag' => '-o',
  1110.            'lder' => 'GCJLD',
  1111.            'ld' => '$(GCJ)',
  1112.            'pure' => 1,
  1113.            'extensions' => ['.java', '.class', '.zip', '.jar']);
  1114.  
  1115. ################################################################
  1116.  
  1117. # Parse the WARNINGS environment variable.
  1118. &parse_WARNINGS;
  1119.  
  1120. # Parse command line.
  1121. &parse_arguments;
  1122.  
  1123. # Do configure.ac scan only once.
  1124. &scan_autoconf_files;
  1125.  
  1126. &fatal ("no `Makefile.am' found or specified\n")
  1127.   if ! @input_files;
  1128.  
  1129. my $automake_has_run = 0;
  1130.  
  1131. do
  1132. {
  1133.   if ($automake_has_run)
  1134.     {
  1135.       &verb ('processing Makefiles another time to fix them up.');
  1136.       &prog_error ('running more than two times should never be needed.')
  1137.     if $automake_has_run >= 2;
  1138.     }
  1139.   $automake_needs_to_reprocess_all_files = 0;
  1140.  
  1141.   # Now do all the work on each file.
  1142.   # This guy must be local otherwise it's private to the loop.
  1143.   use vars '$am_file';
  1144.   local $am_file;
  1145.   foreach $am_file (@input_files)
  1146.     {
  1147.       if (! -f ($am_file . '.am'))
  1148.     {
  1149.       &error ("`$am_file.am' does not exist");
  1150.     }
  1151.       else
  1152.     {
  1153.       &generate_makefile ($output_files{$am_file}, $am_file);
  1154.     }
  1155.     }
  1156.   ++$automake_has_run;
  1157. }
  1158. while ($automake_needs_to_reprocess_all_files);
  1159.  
  1160. exit $exit_code;
  1161.  
  1162. ################################################################
  1163.  
  1164. # Error reporting functions.
  1165.  
  1166. # prog_error ($MESSAGE, [%OPTIONS])
  1167. # -------------------------------
  1168. # Signal a programming error, display $MESSAGE, and exit 1.
  1169. sub prog_error ($;%)
  1170. {
  1171.   my ($msg, %opts) = @_;
  1172.   msg 'automake', '', $msg, %opts;
  1173. }
  1174.  
  1175. # error ($WHERE, $MESSAGE, [%OPTIONS])
  1176. # error ($MESSAGE)
  1177. # ------------------------------------
  1178. # Uncategorized errors.
  1179. sub error ($;$%)
  1180. {
  1181.   my ($where, $msg, %opts) = @_;
  1182.   msg ('error', $where, $msg, %opts);
  1183. }
  1184.  
  1185. # fatal ($WHERE, $MESSAGE, [%OPTIONS])
  1186. # fatal ($MESSAGE)
  1187. # ----------------------------------
  1188. # Fatal errors.
  1189. sub fatal ($;$%)
  1190. {
  1191.   my ($where, $msg, %opts) = @_;
  1192.   msg ('fatal', $where, $msg, %opts);
  1193. }
  1194.  
  1195. # err_var ($VARNAME, $MESSAGE, [%OPTIONS])
  1196. # ----------------------------------------
  1197. # Uncategorized errors about variables.
  1198. sub err_var ($$;%)
  1199. {
  1200.   msg_var ('error', @_);
  1201. }
  1202.  
  1203. # err_target ($TARGETNAME, $MESSAGE, [%OPTIONS])
  1204. # ----------------------------------------------
  1205. # Uncategorized errors about targets.
  1206. sub err_target ($$;%)
  1207. {
  1208.   msg_target ('error', @_);
  1209. }
  1210.  
  1211. # err_cond_target ($COND, $TARGETNAME, $MESSAGE, [%OPTIONS])
  1212. # ----------------------------------------------------------
  1213. # Uncategorized errors about conditional targets.
  1214. sub err_cond_target ($$$;%)
  1215. {
  1216.   msg_cond_target ('error', @_);
  1217. }
  1218.  
  1219. # err_am ($MESSAGE, [%OPTIONS])
  1220. # -----------------------------
  1221. # Uncategorized errors about the current Makefile.am.
  1222. sub err_am ($;%)
  1223. {
  1224.   msg_am ('error', @_);
  1225. }
  1226.  
  1227. # err_ac ($MESSAGE, [%OPTIONS])
  1228. # -----------------------------
  1229. # Uncategorized errors about configure.ac.
  1230. sub err_ac ($;%)
  1231. {
  1232.   msg_ac ('error', @_);
  1233. }
  1234.  
  1235. # msg_cond_var ($CHANNEL, $COND, $VARNAME, $MESSAGE, [%OPTIONS])
  1236. # --------------------------------------------------------------
  1237. # Messages about conditional variable.
  1238. sub msg_cond_var ($$$$;%)
  1239. {
  1240.   my ($channel, $cond, $var, $msg, %opts) = @_;
  1241.   msg $channel, $var_location{$var}{$cond}, $msg, %opts;
  1242. }
  1243.  
  1244. # msg_var ($CHANNEL, $VARNAME, $MESSAGE, [%OPTIONS])
  1245. # --------------------------------------------------
  1246. # Messages about variables.
  1247. sub msg_var ($$$;%)
  1248. {
  1249.   my ($channel, $var, $msg, %opts) = @_;
  1250.   # Don't know which condition is concerned.  Pick any.
  1251.   my $cond = (keys %{$var_value{$var}})[0];
  1252.   msg_cond_var $channel, $cond, $var, $msg, %opts;
  1253. }
  1254.  
  1255. # msg_cond_target ($CHANNEL, $COND, $TARGETNAME, $MESSAGE, [%OPTIONS])
  1256. # --------------------------------------------------------------------
  1257. # Messages about conditional targets.
  1258. sub msg_cond_target ($$$$;%)
  1259. {
  1260.   my ($channel, $cond, $target, $msg, %opts) = @_;
  1261.   msg $channel, $targets{$target}{$cond}, $msg, %opts;
  1262. }
  1263.  
  1264. # msg_target ($CHANNEL, $TARGETNAME, $MESSAGE, [%OPTIONS])
  1265. # --------------------------------------------------------
  1266. # Messages about targets.
  1267. sub msg_target ($$$;%)
  1268. {
  1269.   my ($channel, $target, $msg, %opts) = @_;
  1270.   # Don't know which condition is concerned.  Pick any.
  1271.   my $cond = (keys %{$targets{$target}})[0];
  1272.   msg_cond_target ($channel, $cond, $target, $msg, %opts);
  1273. }
  1274.  
  1275. # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
  1276. # ---------------------------------------
  1277. # Messages about about the current Makefile.am.
  1278. sub msg_am ($$;%)
  1279. {
  1280.   my ($channel, $msg, %opts) = @_;
  1281.   msg $channel, "${am_file}.am", $msg, %opts;
  1282. }
  1283.  
  1284. # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
  1285. # ---------------------------------------
  1286. # Messages about about configure.ac.
  1287. sub msg_ac ($$;%)
  1288. {
  1289.   my ($channel, $msg, %opts) = @_;
  1290.   msg $channel, $configure_ac, $msg, %opts;
  1291. }
  1292.  
  1293. # $BOOL
  1294. # reject_var ($VAR, $ERROR_MSG)
  1295. # -----------------------------
  1296. sub reject_var ($$)
  1297. {
  1298.   my ($var, $msg) = @_;
  1299.   if (variable_defined ($var))
  1300.     {
  1301.       err_var $var, $msg;
  1302.       return 1;
  1303.     }
  1304.   return 0;
  1305. }
  1306.  
  1307. # $BOOL
  1308. # reject_target ($VAR, $ERROR_MSG)
  1309. # --------------------------------
  1310. sub reject_target ($$)
  1311. {
  1312.   my ($target, $msg) = @_;
  1313.   if (target_defined ($target))
  1314.     {
  1315.       err_target $target, $msg;
  1316.       return 1;
  1317.     }
  1318.   return 0;
  1319. }
  1320.  
  1321. # verb ($MESSAGE, [%OPTIONS])
  1322. # ---------------------------
  1323. sub verb ($;%)
  1324. {
  1325.   my ($msg, %opts) = @_;
  1326.   msg 'verb', '', $msg, %opts;
  1327. }
  1328.  
  1329. ################################################################
  1330.  
  1331. # subst ($TEXT)
  1332. # -------------
  1333. # Return a configure-style substitution using the indicated text.
  1334. # We do this to avoid having the substitutions directly in automake.in;
  1335. # when we do that they are sometimes removed and this causes confusion
  1336. # and bugs.
  1337. sub subst ($)
  1338. {
  1339.     my ($text) = @_;
  1340.     return '@' . $text . '@';
  1341. }
  1342.  
  1343. ################################################################
  1344.  
  1345.  
  1346. # $BACKPATH
  1347. # &backname ($REL-DIR)
  1348. # --------------------
  1349. # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
  1350. # For instance `src/foo' => `../..'.
  1351. # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
  1352. sub backname ($)
  1353. {
  1354.     my ($file) = @_;
  1355.     my @res;
  1356.     foreach (split (/\//, $file))
  1357.     {
  1358.     next if $_ eq '.' || $_ eq '';
  1359.     if ($_ eq '..')
  1360.     {
  1361.         pop @res;
  1362.     }
  1363.     else
  1364.     {
  1365.         push (@res, '..');
  1366.     }
  1367.     }
  1368.     return join ('/', @res) || '.';
  1369. }
  1370.  
  1371. ################################################################
  1372.  
  1373. # Pattern that matches all know input extensions (i.e. extensions used
  1374. # by the languages supported by Automake).  Using this pattern
  1375. # (instead of `\..*$') to match extensions allows Automake to support
  1376. # dot-less extensions.
  1377. my $KNOWN_EXTENSIONS_PATTERN = "";
  1378. my @known_extensions_list = ();
  1379.  
  1380. # accept_extensions (@EXTS)
  1381. # -------------------------
  1382. # Update $KNOWN_EXTENSIONS_PATTERN to recognize the extensions
  1383. # listed @EXTS.  Extensions should contain a dot if needed.
  1384. sub accept_extensions (@)
  1385. {
  1386.     push @known_extensions_list, @_;
  1387.     $KNOWN_EXTENSIONS_PATTERN =
  1388.     '(?:' . join ('|', map (quotemeta, @known_extensions_list)) . ')';
  1389. }
  1390.  
  1391. # var_SUFFIXES_trigger ($TYPE, $VALUE)
  1392. # ------------------------------------
  1393. # This is called automagically by macro_define() when SUFFIXES
  1394. # is defined ($TYPE eq '') or appended ($TYPE eq '+').
  1395. # The work here needs to be performed as a side-effect of the
  1396. # macro_define() call because SUFFIXES definitions impact
  1397. # on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN
  1398. # are used when parsing the input am file.
  1399. sub var_SUFFIXES_trigger ($$)
  1400. {
  1401.     my ($type, $value) = @_;
  1402.     accept_extensions (split (' ', $value));
  1403. }
  1404.  
  1405. ################################################################
  1406.  
  1407.  
  1408. # switch_warning ($CATEGORY)
  1409. # --------------------------
  1410. # If $CATEGORY is mumble, turn on the mumble channel.
  1411. # If it's no-mumble, turn mumble off.
  1412. # Alse handle `all' and `none' for completeness.
  1413. sub switch_warning ($)
  1414. {
  1415.   my ($cat) = @_;
  1416.   my $has_no = 0;
  1417.  
  1418.   if ($cat =~ /^no-(.*)$/)
  1419.     {
  1420.       $cat = $1;
  1421.       $has_no = 1;
  1422.     }
  1423.  
  1424.   if ($cat eq 'all')
  1425.     {
  1426.       setup_channel_type 'warning', silent => $has_no;
  1427.     }
  1428.   elsif ($cat eq 'none')
  1429.     {
  1430.       setup_channel_type 'warning', silent => ! $has_no;
  1431.     }
  1432.   elsif ($cat eq 'error')
  1433.     {
  1434.       $warnings_are_errors = ! $has_no;
  1435.       # Set exit code if Perl warns about something
  1436.       # (like uninitialized variables).
  1437.       $SIG{"__WARN__"} =
  1438.     $has_no ? 'DEFAULT' : sub { print STDERR @_; $exit_code = 1; };
  1439.     }
  1440.   elsif (channel_type ($cat) eq 'warning')
  1441.     {
  1442.       setup_channel $cat, silent => $has_no;
  1443.     }
  1444.   else
  1445.     {
  1446.       return 1;
  1447.     }
  1448.   return 0;
  1449. }
  1450.  
  1451. # parse_WARNINGS
  1452. # --------------
  1453. # Honor the WARNINGS environment variable.
  1454. sub parse_WARNINGS ($$)
  1455. {
  1456.   if (exists $ENV{'WARNINGS'})
  1457.     {
  1458.       # Ignore unknown categories.  This is required because WARNINGS
  1459.       # should be honored by many tools.
  1460.       switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
  1461.     }
  1462. }
  1463.  
  1464. # parse_warning ($OPTION, $ARGUMENT)
  1465. # ----------------------------------
  1466. # Parse the argument of --warning=CATEGORY or -WCATEGORY.
  1467. sub parse_warnings ($$)
  1468. {
  1469.   my ($opt, $categories) = @_;
  1470.  
  1471.   foreach my $cat (split (',', $categories))
  1472.     {
  1473.       msg 'unsupported', "unknown warning category `$cat'"
  1474.     if switch_warning $cat;
  1475.     }
  1476. }
  1477.  
  1478. # Parse command line.
  1479. sub parse_arguments ()
  1480. {
  1481.   # Start off as gnu.
  1482.   &set_strictness ('gnu');
  1483.  
  1484.   my %options =
  1485.     (
  1486.      'libdir:s'     => \$libdir,
  1487.      'gnu'         => sub { &set_strictness ('gnu'); },
  1488.      'gnits'         => sub { &set_strictness ('gnits'); },
  1489.      'cygnus'             => \$cygnus_mode,
  1490.      'foreign'             => sub { &set_strictness ('foreign'); },
  1491.      'include-deps'     => sub { $cmdline_use_dependencies = 1; },
  1492.      'i|ignore-deps'     => sub { $cmdline_use_dependencies = 0; },
  1493.      # The current --no-force implementation is bugged, hence the
  1494.      # option is ignored.  It will be fixed in Automake 1.8.
  1495.      'no-force'     => sub { },
  1496.      'f|force-missing'  => \$force_missing,
  1497.      'o|output-dir:s'    => \$output_directory,
  1498.      'a|add-missing'     => \$add_missing,
  1499.      'c|copy'             => \$copy_missing,
  1500.      'v|verbose'     => sub { setup_channel 'verb', silent => 0; },
  1501.      'W|warnings:s'     => \&parse_warnings,
  1502.      # These long options (--Werror and --Wno-error) for backward
  1503.      # compatibility.  Use -Werror and -Wno-error today.
  1504.      'Werror'           => sub { parse_warnings 'W', 'error'; },
  1505.      'Wno-error'        => sub { parse_warnings 'W', 'no-error'; },
  1506.      );
  1507.  
  1508.   use Getopt::Long;
  1509.   Getopt::Long::config ("bundling", "pass_through");
  1510.  
  1511.   # See if --version or --help is used.  We want to process these before
  1512.   # anything else because the GNU Coding Standards require us to
  1513.   # `exit 0' after processing these options, and we can't guarantee this
  1514.   # if we treat other options first.  (Handling other options first
  1515.   # could produce error diagnostics, and in this condition it is
  1516.   # confusing if Automake does `exit 0'.)
  1517.   my %options_1st_pass =
  1518.     (
  1519.      'version' => \&version,
  1520.      'help'    => \&usage,
  1521.      # Recognize all other options (and their arguments) but do nothing.
  1522.      map { $_ => sub {} } (keys %options)
  1523.      );
  1524.   my @ARGV_backup = @ARGV;
  1525.   Getopt::Long::GetOptions %options_1st_pass
  1526.     or exit 1;
  1527.   @ARGV = @ARGV_backup;
  1528.  
  1529.   # Now *really* process the options.  This time we know
  1530.   # that --help and --version are not present.
  1531.   Getopt::Long::GetOptions %options
  1532.     or exit 1;
  1533.  
  1534.   if (defined $output_directory)
  1535.     {
  1536.       msg 'obsolete', "`--output-dir' is deprecated\n";
  1537.     }
  1538.   else
  1539.     {
  1540.       # In the next release we'll remove this entirely.
  1541.       $output_directory = '.';
  1542.     }
  1543.  
  1544.   foreach my $arg (@ARGV)
  1545.     {
  1546.       if ($arg =~ /^-./)
  1547.     {
  1548.       fatal ("unrecognized option `$arg'\n"
  1549.          . "Try `$0 --help' for more information.");
  1550.     }
  1551.  
  1552.       # Handle $local:$input syntax.  Note that we only examine the
  1553.       # first ":" file to see if it is automake input; the rest are
  1554.       # just taken verbatim.  We still keep all the files around for
  1555.       # dependency checking, however.
  1556.       my ($local, $input, @rest) = split (/:/, $arg);
  1557.       if (! $input)
  1558.     {
  1559.       $input = $local;
  1560.     }
  1561.       else
  1562.     {
  1563.       # Strip .in; later on .am is tacked on.  That is how the
  1564.       # automake input file is found.  Maybe not the best way, but
  1565.       # it is easy to explain.
  1566.       $input =~ s/\.in$//
  1567.         or fatal "invalid input file name `$arg'\n.";
  1568.     }
  1569.       push (@input_files, $input);
  1570.       $output_files{$input} = join (':', ($local, @rest));
  1571.     }
  1572.  
  1573.   # Take global strictness from whatever we currently have set.
  1574.   $default_strictness = $strictness;
  1575.   $default_strictness_name = $strictness_name;
  1576. }
  1577.  
  1578. ################################################################
  1579.  
  1580. # Generate a Makefile.in given the name of the corresponding Makefile and
  1581. # the name of the file output by config.status.
  1582. sub generate_makefile
  1583. {
  1584.     my ($output, $makefile) = @_;
  1585.  
  1586.     # Reset all the Makefile.am related variables.
  1587.     &initialize_per_input;
  1588.  
  1589.     # Any warning setting now local to this Makefile.am.
  1590.     &dup_channel_setup;
  1591.     # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
  1592.     # warnings for this file.  So hold any warning issued before
  1593.     # we have processed AUTOMAKE_OPTIONS.
  1594.     &buffer_messages ('warning');
  1595.  
  1596.     # Name of input file ("Makefile.am") and output file
  1597.     # ("Makefile.in").  These have no directory components.
  1598.     $am_file_name = basename ($makefile) . '.am';
  1599.     $in_file_name = basename ($makefile) . '.in';
  1600.  
  1601.     # $OUTPUT is encoded.  If it contains a ":" then the first element
  1602.     # is the real output file, and all remaining elements are input
  1603.     # files.  We don't scan or otherwise deal with these input files,
  1604.     # other than to mark them as dependencies.  See
  1605.     # &scan_autoconf_files for details.
  1606.     my (@secondary_inputs);
  1607.     ($output, @secondary_inputs) = split (/:/, $output);
  1608.  
  1609.     $relative_dir = dirname ($output);
  1610.     $am_relative_dir = dirname ($makefile);
  1611.  
  1612.     &read_main_am_file ($makefile . '.am');
  1613.     if (&handle_options)
  1614.     {
  1615.       # Process buffered warnings.
  1616.       &flush_messages;
  1617.       # Fatal error.  Just return, so we can continue with next file.
  1618.       return;
  1619.     }
  1620.     # Process buffered warnings.
  1621.     &flush_messages;
  1622.  
  1623.     # There are a few install-related variables that you should not define.
  1624.     foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
  1625.       {
  1626.     if (exists $var_owner{$var})
  1627.       {
  1628.         prog_error "\$var_owner{$var}{TRUE} doesn't exist"
  1629.           unless exists $var_owner{$var}{'TRUE'};
  1630.         reject_var $var, "`$var' should not be defined"
  1631.           if $var_owner{$var}{'TRUE'} != VAR_AUTOMAKE;
  1632.       }
  1633.       }
  1634.  
  1635.     # Catch some obsolete variables.
  1636.     msg_var ('obsolete', 'INCLUDES',
  1637.          "`INCLUDES' is the old name for `AM_CPPFLAGS'")
  1638.       if variable_defined ('INCLUDES');
  1639.  
  1640.     # At the toplevel directory, we might need config.guess, config.sub
  1641.     # or libtool scripts (ltconfig and ltmain.sh).
  1642.     if ($relative_dir eq '.')
  1643.     {
  1644.         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
  1645.         # config.sub.
  1646.         require_conf_file ($canonical_location, FOREIGN,
  1647.                'config.guess', 'config.sub')
  1648.       if $seen_canonical;
  1649.     }
  1650.  
  1651.     push (@sources, '$(SOURCES)')
  1652.     if variable_defined ('SOURCES');
  1653.  
  1654.     # Must do this after reading .am file.  See read_main_am_file to
  1655.     # understand weird tricks we play there with variables.
  1656.     &define_variable ('subdir', $relative_dir);
  1657.  
  1658.     # Check first, because we might modify some state.
  1659.     &check_cygnus;
  1660.     &check_gnu_standards;
  1661.     &check_gnits_standards;
  1662.  
  1663.     &handle_configure ($output, $makefile, @secondary_inputs);
  1664.     &handle_gettext;
  1665.     &handle_libraries;
  1666.     &handle_ltlibraries;
  1667.     &handle_programs;
  1668.     &handle_scripts;
  1669.  
  1670.     # This must run first so that the ANSI2KNR definition is generated
  1671.     # before it is used by the _.c rules.  We have to do this because
  1672.     # a variable which is used in a dependency must be defined before
  1673.     # the target, or else make won't properly see it.
  1674.     &handle_compile;
  1675.     # This must be run after all the sources are scanned.
  1676.     &handle_languages;
  1677.  
  1678.     # We have to run this after dealing with all the programs.
  1679.     &handle_libtool;
  1680.  
  1681.     # Re-init SOURCES.  FIXME: other code shouldn't depend on this
  1682.     # (but currently does).
  1683.     macro_define ('SOURCES', VAR_AUTOMAKE, '', 'TRUE', "@sources", 'internal');
  1684.     define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
  1685.  
  1686.     &handle_multilib;
  1687.     &handle_texinfo;
  1688.     &handle_emacs_lisp;
  1689.     &handle_python;
  1690.     &handle_java;
  1691.     &handle_man_pages;
  1692.     &handle_data;
  1693.     &handle_headers;
  1694.     &handle_subdirs;
  1695.     &handle_tags;
  1696.     &handle_minor_options;
  1697.     &handle_tests;
  1698.  
  1699.     # This must come after most other rules.
  1700.     &handle_dist ($makefile);
  1701.  
  1702.     &handle_footer;
  1703.     &do_check_merge_target;
  1704.     &handle_all ($output);
  1705.  
  1706.     # FIXME: Gross!
  1707.     if (variable_defined ('lib_LTLIBRARIES') &&
  1708.     variable_defined ('bin_PROGRAMS'))
  1709.     {
  1710.     $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
  1711.     }
  1712.  
  1713.     &handle_install;
  1714.     &handle_clean;
  1715.     &handle_factored_dependencies;
  1716.  
  1717.     check_typos ();
  1718.  
  1719.     if (! -d ($output_directory . '/' . $am_relative_dir))
  1720.     {
  1721.     mkdir ($output_directory . '/' . $am_relative_dir, 0755);
  1722.     }
  1723.  
  1724.     my ($out_file) = $output_directory . '/' . $makefile . ".in";
  1725.     if (! $force_generation && -e $out_file)
  1726.     {
  1727.     my ($am_time) = (stat ($makefile . '.am'))[9];
  1728.     my ($in_time) = (stat ($out_file))[9];
  1729.     # FIXME: should cache these times.
  1730.     my ($conf_time) = (stat ($configure_ac))[9];
  1731.     # FIXME: how to do unsigned comparison?
  1732.     if ($am_time < $in_time || $am_time < $conf_time)
  1733.     {
  1734.         # No need to update.
  1735.         return;
  1736.     }
  1737.     if (-f 'aclocal.m4')
  1738.     {
  1739.         my ($acl_time) = (stat _)[9];
  1740.         return if ($am_time < $acl_time);
  1741.     }
  1742.     }
  1743.  
  1744.     if (-e "$out_file")
  1745.     {
  1746.     unlink ($out_file)
  1747.         or fatal "cannot remove $out_file: $!\n";
  1748.     }
  1749.     my $gm_file = new Automake::XFile "> $out_file";
  1750.     verb "creating $makefile.in";
  1751.  
  1752.     print $gm_file $output_vars;
  1753.     # We make sure that `all:' is the first target.
  1754.     print $gm_file $output_all;
  1755.     print $gm_file $output_header;
  1756.     print $gm_file $output_rules;
  1757.     print $gm_file $output_trailer;
  1758.  
  1759.     # Back out any warning setting.
  1760.     &drop_channel_setup;
  1761. }
  1762.  
  1763. ################################################################
  1764.  
  1765. # A version is a string that looks like
  1766. #   MAJOR.MINOR[.MICRO][ALPHA][-FORK]
  1767. # where
  1768. #   MAJOR, MINOR, and MICRO are digits, ALPHA is a character, and
  1769. # FORK any alphanumeric word.
  1770. # Usually, ALPHA is used to label alpha releases or intermediate snapshots,
  1771. # FORK is used for CVS branches or patched releases, and MICRO is used
  1772. # for bug fixes releases on the MAJOR.MINOR branch.
  1773. #
  1774. # For the purpose of ordering, 1.4 is the same as 1.4.0, but 1.4g is
  1775. # the same as 1.4.99g.  The FORK identifier is ignored in the
  1776. # ordering, except when it looks like -pMINOR[ALPHA]: some versions
  1777. # were labelled like 1.4-p3a, this is the same as an alpha release
  1778. # labelled 1.4.3a.  Yes it's horrible, but Automake did not support
  1779. # two-dot versions in the past.
  1780.  
  1781. # version_split (VERSION)
  1782. # -----------------------
  1783. # Split a version string into the corresponding (MAJOR, MINOR, MICRO,
  1784. # ALPHA, FORK) tuple.  For instance "1.4g" would be split into
  1785. # (1, 4, 99, 'g', '').
  1786. # Return () on error.
  1787. sub version_split ($)
  1788. {
  1789.     my ($ver) = @_;
  1790.  
  1791.     # Special case for versions like 1.4-p2a.
  1792.     if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/)
  1793.     {
  1794.     return ($1, $2, $3, $4 || '', '');
  1795.     }
  1796.     # Common case.
  1797.     elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/)
  1798.     {
  1799.     return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || '');
  1800.     }
  1801.     return ();
  1802. }
  1803.  
  1804. # version_compare (\@LVERSION, \@RVERSION)
  1805. # ----------------------------------------
  1806. # Return 1 if LVERSION > RVERSION,
  1807. #       -1 if LVERSION < RVERSION,
  1808. #        0 if LVERSION = RVERSION.
  1809. sub version_compare (\@\@)
  1810. {
  1811.     my @l = @{$_[0]};
  1812.     my @r = @{$_[1]};
  1813.  
  1814.     for my $i (0, 1, 2)
  1815.     {
  1816.     return 1  if ($l[$i] > $r[$i]);
  1817.     return -1 if ($l[$i] < $r[$i]);
  1818.     }
  1819.     for my $i (3, 4)
  1820.     {
  1821.     return 1  if ($l[$i] gt $r[$i]);
  1822.     return -1 if ($l[$i] lt $r[$i]);
  1823.     }
  1824.     return 0;
  1825. }
  1826.  
  1827. # Handles the logic of requiring a version number in AUTOMAKE_OPTIONS.
  1828. # Return 0 if the required version is satisfied, 1 otherwise.
  1829. sub version_check ($)
  1830. {
  1831.   my ($required) = @_;
  1832.   my @version = version_split $VERSION;
  1833.   my @required = version_split $required;
  1834.  
  1835.   prog_error "version is incorrect: $VERSION"
  1836.     if $#version == -1;
  1837.  
  1838.   # This should not happen, because process_option_list and split_version
  1839.   # use similar regexes.
  1840.   prog_error "required version is incorrect: $required"
  1841.     if $#required == -1;
  1842.  
  1843.   # If we require 3.4n-foo then we require something
  1844.   # >= 3.4n, with the `foo' fork identifier.
  1845.   return 1
  1846.     if ($required[4] ne '' && $required[4] ne $version[4]);
  1847.  
  1848.   return 0 > version_compare @version, @required;
  1849. }
  1850.  
  1851. # $BOOL
  1852. # process_option_list ($CONFIG, @OPTIONS)
  1853. # ------------------------------
  1854. # Process a list of options.  Return 1 on error, 0 otherwise.
  1855. # This is a helper for handle_options.  CONFIG is true if we're
  1856. # handling global options.
  1857. sub process_option_list
  1858. {
  1859.   my ($config, @list) = @_;
  1860.  
  1861.   # FIXME: We should disallow conditional definitions of AUTOMAKE_OPTIONS.
  1862.   my $where = ($config ?
  1863.            $seen_init_automake :
  1864.            $var_location{'AUTOMAKE_OPTIONS'}{'TRUE'});
  1865.  
  1866.   foreach (@list)
  1867.     {
  1868.       $options{$_} = $where;
  1869.       if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
  1870.     {
  1871.       &set_strictness ($_);
  1872.     }
  1873.       elsif ($_ eq 'cygnus')
  1874.     {
  1875.       $cygnus_mode = $where;
  1876.     }
  1877.       elsif (/^(.*\/)?ansi2knr$/)
  1878.     {
  1879.       # An option like "../lib/ansi2knr" is allowed.  With no
  1880.       # path prefix, we assume the required programs are in this
  1881.       # directory.  We save the actual option for later.
  1882.       $options{'ansi2knr'} = [$_, $where];
  1883.     }
  1884.       elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
  1885.          || $_ eq 'dist-shar' || $_ eq 'dist-zip'
  1886.          || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
  1887.          || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
  1888.          || $_ eq 'readme-alpha' || $_ eq 'check-news'
  1889.          || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
  1890.          || $_ eq 'no-exeext' || $_ eq 'no-define'
  1891.          || $_ eq 'std-options')
  1892.     {
  1893.       # Explicitly recognize these.
  1894.     }
  1895.       elsif ($_ eq 'no-dependencies')
  1896.     {
  1897.       $use_dependencies = 0;
  1898.     }
  1899.       elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
  1900.     {
  1901.       # Got a version number.
  1902.       if (version_check $&)
  1903.         {
  1904.           error ($where, "require Automake $_, but have $VERSION",
  1905.              uniq_scope => US_GLOBAL);
  1906.         return 1;
  1907.         }
  1908.     }
  1909.       elsif (/^(?:--warnings=|-W)(.*)$/)
  1910.     {
  1911.       foreach my $cat (split (',', $1))
  1912.         {
  1913.           msg 'unsupported', $where, "unknown warning category `$cat'"
  1914.         if switch_warning $cat;
  1915.         }
  1916.     }
  1917.       else
  1918.     {
  1919.       error ($where, "option `$_' not recognized",
  1920.          uniq_scope => US_GLOBAL);
  1921.       return 1;
  1922.     }
  1923.     }
  1924. }
  1925.  
  1926. # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
  1927. sub handle_options
  1928. {
  1929.     # Process global options first so that more specific options can
  1930.     # override.
  1931.     if (&process_option_list (1, split (' ', $global_options)))
  1932.     {
  1933.     return 1;
  1934.     }
  1935.  
  1936.     if (variable_defined ('AUTOMAKE_OPTIONS'))
  1937.     {
  1938.     if (&process_option_list (0, &variable_value_as_list_recursive ('AUTOMAKE_OPTIONS', '')))
  1939.     {
  1940.         return 1;
  1941.     }
  1942.     }
  1943.  
  1944.     if ($strictness == GNITS)
  1945.     {
  1946.     $options{'readme-alpha'} = 1;
  1947.     $options{'std-options'} = 1;
  1948.     $options{'check-news'} = 1;
  1949.     }
  1950.  
  1951.     return 0;
  1952. }
  1953.  
  1954.  
  1955. # get_object_extension ($OUT)
  1956. # ---------------------------
  1957. # Return object extension.  Just once, put some code into the output.
  1958. # OUT is the name of the output file
  1959. sub get_object_extension
  1960. {
  1961.     my ($out) = @_;
  1962.  
  1963.     # Maybe require libtool library object files.
  1964.     my $extension = '.$(OBJEXT)';
  1965.     $extension = '.lo' if ($out =~ /\.la$/);
  1966.  
  1967.     # Check for automatic de-ANSI-fication.
  1968.     $extension = '$U' . $extension
  1969.       if defined $options{'ansi2knr'};
  1970.  
  1971.     $get_object_extension_was_run = 1;
  1972.  
  1973.     return $extension;
  1974. }
  1975.  
  1976.  
  1977. # Call finish function for each language that was used.
  1978. sub handle_languages
  1979. {
  1980.     if ($use_dependencies)
  1981.     {
  1982.     # Include auto-dep code.  Don't include it if DEP_FILES would
  1983.     # be empty.
  1984.     if (&saw_sources_p (0) && keys %dep_files)
  1985.     {
  1986.         # Set location of depcomp.
  1987.         &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
  1988.         &define_variable ('am__depfiles_maybe', 'depfiles');
  1989.  
  1990.         require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
  1991.  
  1992.         my @deplist = sort keys %dep_files;
  1993.  
  1994.         # We define this as a conditional variable because BSD
  1995.         # make can't handle backslashes for continuing comments on
  1996.         # the following line.
  1997.         define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
  1998.  
  1999.         # Generate each `include' individually.  Irix 6 make will
  2000.         # not properly include several files resulting from a
  2001.         # variable expansion; generating many separate includes
  2002.         # seems safest.
  2003.         $output_rules .= "\n";
  2004.         foreach my $iter (@deplist)
  2005.          {
  2006.         $output_rules .= (subst ('AMDEP_TRUE')
  2007.                   . subst ('am__include')
  2008.                   . ' '
  2009.                   . subst ('am__quote')
  2010.                   . $iter
  2011.                   . subst ('am__quote')
  2012.                   . "\n");
  2013.         }
  2014.  
  2015.         # Compute the set of directories to remove in distclean-depend.
  2016.         my @depdirs = uniq (map { dirname ($_) } @deplist);
  2017.         $output_rules .= &file_contents ('depend',
  2018.                          DEPDIRS => "@depdirs");
  2019.     }
  2020.     }
  2021.     else
  2022.     {
  2023.     &define_variable ('depcomp', '');
  2024.     &define_variable ('am__depfiles_maybe', '');
  2025.     }
  2026.  
  2027.     my %done;
  2028.  
  2029.     # Is the c linker needed?
  2030.     my $needs_c = 0;
  2031.     foreach my $ext (sort keys %extension_seen)
  2032.     {
  2033.     next unless $extension_map{$ext};
  2034.  
  2035.     my $lang = $languages{$extension_map{$ext}};
  2036.  
  2037.     my $rule_file = $lang->rule_file || 'depend2';
  2038.  
  2039.     # Get information on $LANG.
  2040.     my $pfx = $lang->autodep;
  2041.     my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
  2042.  
  2043.     my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
  2044.              ? 'AMDEP' : 'FALSE');
  2045.     my $FASTDEP = (($use_dependencies && $lang->autodep ne 'no')
  2046.                ? ('am__fastdep' . $fpfx) : 'FALSE');
  2047.  
  2048.     my %transform = ('EXT'     => $ext,
  2049.              'PFX'     => $pfx,
  2050.              'FPFX'    => $fpfx,
  2051.              'AMDEP'   => $AMDEP,
  2052.              'FASTDEP' => $FASTDEP,
  2053.              '-c'      => $lang->compile_flag || '',
  2054.              'MORE-THAN-ONE'
  2055.                        => (count_files_for_language ($lang->name) > 1));
  2056.  
  2057.     # Generate the appropriate rules for this extension.
  2058.     if (($use_dependencies && $lang->autodep ne 'no')
  2059.         || defined $lang->compile)
  2060.     {
  2061.         # Some C compilers don't support -c -o.  Use it only if really
  2062.         # needed.
  2063.         my $output_flag = $lang->output_flag || '';
  2064.         $output_flag = '-o'
  2065.           if (! $output_flag
  2066.           && $lang->name eq 'c'
  2067.           && defined $options{'subdir-objects'});
  2068.  
  2069.         # Compute a possible derived extension.
  2070.         # This is not used by depend2.am.
  2071.         my $der_ext = (&{$lang->output_extensions} ($ext))[0];
  2072.  
  2073.         $output_rules .=
  2074.           file_contents ($rule_file,
  2075.                  %transform,
  2076.                  'GENERIC'   => 1,
  2077.  
  2078.                  'DERIVED-EXT' => $der_ext,
  2079.  
  2080.                  # In this situation we know that the
  2081.                  # object is in this directory, so
  2082.                  # $(DEPDIR) is the correct location for
  2083.                  # dependencies.
  2084.                  'DEPBASE'   => '$(DEPDIR)/$*',
  2085.                  'BASE'      => '$*',
  2086.                  'SOURCE'    => '$<',
  2087.                  'OBJ'       => '$@',
  2088.                  'OBJOBJ'    => '$@',
  2089.                  'LTOBJ'     => '$@',
  2090.  
  2091.                  'COMPILE'   => '$(' . $lang->compiler . ')',
  2092.                  'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
  2093.                  '-o'        => $output_flag);
  2094.     }
  2095.  
  2096.     # Now include code for each specially handled object with this
  2097.     # language.
  2098.     my %seen_files = ();
  2099.     foreach my $file (@{$lang_specific_files{$lang->name}})
  2100.     {
  2101.         my ($derived, $source, $obj, $myext) = split (' ', $file);
  2102.  
  2103.         # We might see a given object twice, for instance if it is
  2104.         # used under different conditions.
  2105.         next if defined $seen_files{$obj};
  2106.         $seen_files{$obj} = 1;
  2107.  
  2108.         prog_error ("found " . $lang->name .
  2109.             " in handle_languages, but compiler not defined")
  2110.           unless defined $lang->compile;
  2111.  
  2112.         my $obj_compile = $lang->compile;
  2113.  
  2114.         # Rewrite each occurrence of `AM_$flag' in the compile
  2115.         # rule into `${derived}_$flag' if it exists.
  2116.         for my $flag (@{$lang->flags})
  2117.           {
  2118.         my $val = "${derived}_$flag";
  2119.         $obj_compile =~ s/\(AM_$flag\)/\($val\)/
  2120.           if variable_defined ($val);
  2121.           }
  2122.  
  2123.         my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
  2124.  
  2125.         # We _need_ `-o' for per object rules.
  2126.         my $output_flag = $lang->output_flag || '-o';
  2127.  
  2128.         my $depbase = dirname ($obj);
  2129.         $depbase = ''
  2130.         if $depbase eq '.';
  2131.         $depbase .= '/'
  2132.         unless $depbase eq '';
  2133.         $depbase .= '$(DEPDIR)/' . basename ($obj);
  2134.  
  2135.         # Support for deansified files in subdirectories is ugly
  2136.         # enough to deserve an explanation.
  2137.         #
  2138.         # A Note about normal ansi2knr processing first.  On
  2139.         #
  2140.         #   AUTOMAKE_OPTIONS = ansi2knr
  2141.         #   bin_PROGRAMS = foo
  2142.         #   foo_SOURCES = foo.c
  2143.         #
  2144.         # we generate rules similar to:
  2145.         #
  2146.         #   foo: foo$U.o; link ...
  2147.         #   foo$U.o: foo$U.c; compile ...
  2148.         #   foo_.c: foo.c; ansi2knr ...
  2149.         #
  2150.         # this is fairly compact, and will call ansi2knr depending
  2151.         # on the value of $U (`' or `_').
  2152.         #
  2153.         # It's harder with subdir sources. On
  2154.         #
  2155.         #   AUTOMAKE_OPTIONS = ansi2knr
  2156.         #   bin_PROGRAMS = foo
  2157.         #   foo_SOURCES = sub/foo.c
  2158.         #
  2159.         # we have to create foo_.c in the current directory.
  2160.         # (Unless the user asks 'subdir-objects'.)  This is important
  2161.         # in case the same file (`foo.c') is compiled from other
  2162.         # directories with different cpp options: foo_.c would
  2163.         # be preprocessed for only one set of options if it were
  2164.         # put in the subdirectory.
  2165.         #
  2166.         # Because foo$U.o must be built from either foo_.c or
  2167.         # sub/foo.c we can't be as concise as in the first example.
  2168.         # Instead we output
  2169.         #
  2170.         #   foo: foo$U.o; link ...
  2171.         #   foo_.o: foo_.c; compile ...
  2172.         #   foo.o: sub/foo.c; compile ...
  2173.         #   foo_.c: foo.c; ansi2knr ...
  2174.         #
  2175.         # This is why we'll now transform $rule_file twice
  2176.         # if we detect this case.
  2177.         # A first time we output the compile rule with `$U'
  2178.         # replaced by `_' and the source directory removed,
  2179.         # and another time we simply remove `$U'.
  2180.         #
  2181.         # Note that at this point $source (as computed by
  2182.         # &handle_single_transform_list) is `sub/foo$U.c'.
  2183.         # This can be confusing: it can be used as-is when
  2184.         # subdir-objects is set, otherwise you have to know
  2185.         # it really means `foo_.c' or `sub/foo.c'.
  2186.         my $objdir = dirname ($obj);
  2187.         my $srcdir = dirname ($source);
  2188.         if ($lang->ansi && $obj =~ /\$U/)
  2189.           {
  2190.         prog_error "`$obj' contains \$U, but `$source' doesn't."
  2191.           if $source !~ /\$U/;
  2192.  
  2193.         (my $source_ = $source) =~ s/\$U/_/g;
  2194.         # Explicitly clean the _.c files if they are in
  2195.         # a subdirectory. (In the current directory they get
  2196.         # erased by a `rm -f *_.c' rule.)
  2197.         $clean_files{$source_} = MOSTLY_CLEAN
  2198.           if $objdir ne '.';
  2199.         # Output an additional rule if _.c and .c are not in
  2200.         # the same directory.  (_.c is always in $objdir.)
  2201.         if ($objdir ne $srcdir)
  2202.           {
  2203.             (my $obj_ = $obj) =~ s/\$U/_/g;
  2204.             (my $depbase_ = $depbase) =~ s/\$U/_/g;
  2205.             $source_ = basename ($source_);
  2206.  
  2207.             $output_rules .=
  2208.               file_contents ($rule_file,
  2209.                      %transform,
  2210.                      GENERIC   => 0,
  2211.  
  2212.                      DEPBASE   => $depbase_,
  2213.                      BASE      => $obj_,
  2214.                      SOURCE    => $source_,
  2215.                      OBJ       => "$obj_$myext",
  2216.                      OBJOBJ    => "$obj_.obj",
  2217.                      LTOBJ     => "$obj_.lo",
  2218.  
  2219.                      COMPILE   => $obj_compile,
  2220.                      LTCOMPILE => $obj_ltcompile,
  2221.                      -o        => $output_flag);
  2222.             $obj =~ s/\$U//g;
  2223.             $depbase =~ s/\$U//g;
  2224.             $source =~ s/\$U//g;
  2225.           }
  2226.           }
  2227.  
  2228.         $output_rules .=
  2229.           file_contents ($rule_file,
  2230.                  (%transform,
  2231.                   'GENERIC'   => 0,
  2232.  
  2233.                   'DEPBASE'   => $depbase,
  2234.                   'BASE'      => $obj,
  2235.                   'SOURCE'    => $source,
  2236.                   # Use $myext and not `.o' here, in case
  2237.                   # we are actually building a new source
  2238.                   # file -- e.g. via yacc.
  2239.                   'OBJ'       => "$obj$myext",
  2240.                   'OBJOBJ'    => "$obj.obj",
  2241.                   'LTOBJ'     => "$obj.lo",
  2242.  
  2243.                   'COMPILE'   => $obj_compile,
  2244.                   'LTCOMPILE' => $obj_ltcompile,
  2245.                   '-o'        => $output_flag));
  2246.     }
  2247.  
  2248.     # The rest of the loop is done once per language.
  2249.     next if defined $done{$lang};
  2250.     $done{$lang} = 1;
  2251.  
  2252.     # Load the language dependent Makefile chunks.
  2253.     my %lang = map { uc ($_) => 0 } keys %languages;
  2254.     $lang{uc ($lang->name)} = 1;
  2255.     $output_rules .= file_contents ('lang-compile', %transform, %lang);
  2256.  
  2257.     # If the source to a program consists entirely of code from a
  2258.     # `pure' language, for instance C++ for Fortran 77, then we
  2259.     # don't need the C compiler code.  However if we run into
  2260.     # something unusual then we do generate the C code.  There are
  2261.     # probably corner cases here that do not work properly.
  2262.     # People linking Java code to Fortran code deserve pain.
  2263.     $needs_c ||= ! $lang->pure;
  2264.  
  2265.     define_compiler_variable ($lang)
  2266.       if ($lang->compile);
  2267.  
  2268.     define_linker_variable ($lang)
  2269.       if ($lang->link);
  2270.  
  2271.     require_variables ("$am_file.am", $lang->Name . " source seen",
  2272.                'TRUE', @{$lang->config_vars});
  2273.  
  2274.     # Call the finisher.
  2275.     $lang->finish;
  2276.  
  2277.     # Flags listed in `->flags' are user variables (per GNU Standards),
  2278.     # they should not be overridden in the Makefile...
  2279.     my @dont_override = @{$lang->flags};
  2280.     # ... and so is LDFLAGS.
  2281.     push @dont_override, 'LDFLAGS' if $lang->link;
  2282.  
  2283.     foreach my $flag (@dont_override)
  2284.       {
  2285.         if (exists $var_owner{$flag})
  2286.           {
  2287.         for my $cond (keys %{$var_owner{$flag}})
  2288.           {
  2289.             if ($var_owner{$flag}{$cond} == VAR_MAKEFILE)
  2290.               {
  2291.             msg_cond_var ('gnu', $cond, $flag,
  2292.                       "`$flag' is a user variable, "
  2293.                       . "you should not override it;\n"
  2294.                       . "use `AM_$flag' instead.");
  2295.               }
  2296.           }
  2297.           }
  2298.       }
  2299.     }
  2300.  
  2301.     # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
  2302.     # suffix rule was learned), don't bother with the C stuff.  But if
  2303.     # anything else creeps in, then use it.
  2304.     $needs_c = 1
  2305.       if $need_link || ((scalar keys %$suffix_rules)
  2306.             - (scalar keys %$suffix_rules_default)) > 1;
  2307.  
  2308.     if ($needs_c)
  2309.       {
  2310.     &define_compiler_variable ($languages{'c'})
  2311.       unless defined $done{$languages{'c'}};
  2312.     define_linker_variable ($languages{'c'});
  2313.       }
  2314. }
  2315.  
  2316. # Check to make sure a source defined in LIBOBJS is not explicitly
  2317. # mentioned.  This is a separate function (as opposed to being inlined
  2318. # in handle_source_transform) because it isn't always appropriate to
  2319. # do this check.
  2320. sub check_libobjs_sources
  2321. {
  2322.   my ($one_file, $unxformed) = @_;
  2323.  
  2324.   foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
  2325.               'dist_EXTRA_', 'nodist_EXTRA_')
  2326.     {
  2327.         my @files;
  2328.     if (variable_defined ($prefix . $one_file . '_SOURCES'))
  2329.     {
  2330.         @files = &variable_value_as_list_recursive (
  2331.                 ($prefix . $one_file . '_SOURCES'),
  2332.                 'all');
  2333.     }
  2334.     elsif ($prefix eq '')
  2335.     {
  2336.         @files = ($unxformed . '.c');
  2337.     }
  2338.     else
  2339.     {
  2340.         next;
  2341.     }
  2342.  
  2343.     foreach my $file (@files)
  2344.     {
  2345.       err_var ($prefix . $one_file . '_SOURCES',
  2346.            "automatically discovered file `$file' should not" .
  2347.            " be explicitly mentioned")
  2348.         if defined $libsources{$file};
  2349.     }
  2350.     }
  2351. }
  2352.  
  2353.  
  2354. # @OBJECTS
  2355. # handle_single_transform_list ($VAR, $TOPPARENT, $DERIVED, $OBJ, @FILES)
  2356. # -----------------------------------------------------------------------
  2357. # Does much of the actual work for handle_source_transform.
  2358. # Arguments are:
  2359. #   $VAR is the name of the variable that the source filenames come from
  2360. #   $TOPPARENT is the name of the _SOURCES variable which is being processed
  2361. #   $DERIVED is the name of resulting executable or library
  2362. #   $OBJ is the object extension (e.g., `$U.lo')
  2363. #   @FILES is the list of source files to transform
  2364. # Result is a list of the names of objects
  2365. # %linkers_used will be updated with any linkers needed
  2366. sub handle_single_transform_list ($$$$@)
  2367. {
  2368.     my ($var, $topparent, $derived, $obj, @files) = @_;
  2369.     my @result = ();
  2370.     my $nonansi_obj = $obj;
  2371.     $nonansi_obj =~ s/\$U//g;
  2372.  
  2373.     # Turn sources into objects.  We use a while loop like this
  2374.     # because we might add to @files in the loop.
  2375.     while (scalar @files > 0)
  2376.     {
  2377.     $_ = shift @files;
  2378.  
  2379.         # Configure substitutions in _SOURCES variables are errors.
  2380.         if (/^\@.*\@$/)
  2381.         {
  2382.             err_var ($var,
  2383.              "`$var' includes configure substitution `$_', and is " .
  2384.              "referred to\nfrom `$topparent': configure " .
  2385.              "substitutions are not allowed\nin _SOURCES variables");
  2386.             next;
  2387.         }
  2388.  
  2389.         # If the source file is in a subdirectory then the `.o' is put
  2390.         # into the current directory, unless the subdir-objects option
  2391.         # is in effect.
  2392.  
  2393.         # Split file name into base and extension.
  2394.         next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
  2395.         my $full = $_;
  2396.         my $directory = $1 || '';
  2397.         my $base = $2;
  2398.         my $extension = $3;
  2399.  
  2400.         # We must generate a rule for the object if it requires its own flags.
  2401.         my $renamed = 0;
  2402.         my ($linker, $object);
  2403.  
  2404.     # This records whether we've seen a derived source file (eg,
  2405.     # yacc output).
  2406.     my $derived_source = 0;
  2407.  
  2408.     # This holds the `aggregate context' of the file we are
  2409.     # currently examining.  If the file is compiled with
  2410.     # per-object flags, then it will be the name of the object.
  2411.     # Otherwise it will be `AM'.  This is used by the target hook
  2412.     # language function.
  2413.     my $aggregate = 'AM';
  2414.  
  2415.         $extension = &derive_suffix ($extension, $nonansi_obj);
  2416.         my $lang;
  2417.         if ($extension_map{$extension} &&
  2418.             ($lang = $languages{$extension_map{$extension}}))
  2419.     {
  2420.             # Found the language, so see what it says.
  2421.             &saw_extension ($extension);
  2422.  
  2423.             # Note: computed subr call.  The language rewrite function
  2424.             # should return one of the LANG_* constants.  It could
  2425.             # also return a list whose first value is such a constant
  2426.             # and whose second value is a new source extension which
  2427.             # should be applied.  This means this particular language
  2428.             # generates another source file which we must then process
  2429.             # further.
  2430.             my $subr = 'lang_' . $lang->name . '_rewrite';
  2431.             my ($r, $source_extension)
  2432.         = & $subr ($directory, $base, $extension);
  2433.             # Skip this entry if we were asked not to process it.
  2434.             next if $r == LANG_IGNORE;
  2435.  
  2436.             # Now extract linker and other info.
  2437.             $linker = $lang->linker;
  2438.  
  2439.             my $this_obj_ext;
  2440.         if (defined $source_extension)
  2441.         {
  2442.         $this_obj_ext = $source_extension;
  2443.         $derived_source = 1;
  2444.         }
  2445.         elsif ($lang->ansi)
  2446.         {
  2447.         $this_obj_ext = $obj;
  2448.         }
  2449.         else
  2450.         {
  2451.         $this_obj_ext = $nonansi_obj;
  2452.         }
  2453.         $object = $base . $this_obj_ext;
  2454.  
  2455.         # Do we have per-executable flags for this executable?
  2456.         my $have_per_exec_flags = 0;
  2457.         foreach my $flag (@{$lang->flags})
  2458.           {
  2459.         if (variable_defined ("${derived}_$flag"))
  2460.           {
  2461.             $have_per_exec_flags = 1;
  2462.             last;
  2463.           }
  2464.           }
  2465.  
  2466.             if ($have_per_exec_flags)
  2467.             {
  2468.                 # We have a per-executable flag in effect for this
  2469.                 # object.  In this case we rewrite the object's
  2470.                 # name to ensure it is unique.  We also require
  2471.                 # the `compile' program to deal with compilers
  2472.                 # where `-c -o' does not work.
  2473.  
  2474.                 # We choose the name `DERIVED_OBJECT' to ensure
  2475.                 # (1) uniqueness, and (2) continuity between
  2476.                 # invocations.  However, this will result in a
  2477.                 # name that is too long for losing systems, in
  2478.                 # some situations.  So we provide _SHORTNAME to
  2479.                 # override.
  2480.  
  2481.                 my $dname = $derived;
  2482.                 if (variable_defined ($derived . '_SHORTNAME'))
  2483.                 {
  2484.                     # FIXME: should use the same conditional as
  2485.                     # the _SOURCES variable.  But this is really
  2486.                     # silly overkill -- nobody should have
  2487.                     # conditional shortnames.
  2488.                     $dname = &variable_value ($derived . '_SHORTNAME');
  2489.                 }
  2490.                 $object = $dname . '-' . $object;
  2491.  
  2492.                 require_conf_file ("$am_file.am", FOREIGN, 'compile')
  2493.                     if $lang->name eq 'c';
  2494.  
  2495.         prog_error ($lang->name . " flags defined without compiler")
  2496.           if ! defined $lang->compile;
  2497.  
  2498.                 $renamed = 1;
  2499.             }
  2500.  
  2501.             # If rewrite said it was ok, put the object into a
  2502.             # subdir.
  2503.             if ($r == LANG_SUBDIR && $directory ne '')
  2504.             {
  2505.                 $object = $directory . '/' . $object;
  2506.             }
  2507.  
  2508.             # If doing dependency tracking, then we can't print
  2509.             # the rule.  If we have a subdir object, we need to
  2510.             # generate an explicit rule.  Actually, in any case
  2511.             # where the object is not in `.' we need a special
  2512.             # rule.  The per-object rules in this case are
  2513.             # generated later, by handle_languages.
  2514.             if ($renamed || $directory ne '')
  2515.             {
  2516.                 my $obj_sans_ext = substr ($object, 0,
  2517.                        - length ($this_obj_ext));
  2518.         my $full_ansi = $full;
  2519.         if ($lang->ansi && defined $options{'ansi2knr'})
  2520.           {
  2521.             $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/;
  2522.             $obj_sans_ext .= '$U';
  2523.           }
  2524.  
  2525.         my $val = ("$full_ansi $obj_sans_ext "
  2526.                # Only use $this_obj_ext in the derived
  2527.                # source case because in the other case we
  2528.                # *don't* want $(OBJEXT) to appear here.
  2529.                . ($derived_source ? $this_obj_ext : '.o'));
  2530.  
  2531.         # If we renamed the object then we want to use the
  2532.         # per-executable flag name.  But if this is simply a
  2533.         # subdir build then we still want to use the AM_ flag
  2534.         # name.
  2535.         if ($renamed)
  2536.         {
  2537.             $val = "$derived $val";
  2538.             $aggregate = $derived;
  2539.         }
  2540.         else
  2541.         {
  2542.             $val = "AM $val";
  2543.         }
  2544.  
  2545.         # Each item on this list is a string consisting of
  2546.         # four space-separated values: the derived flag prefix
  2547.         # (eg, for `foo_CFLAGS', it is `foo'), the name of the
  2548.         # source file, the base name of the output file, and
  2549.         # the extension for the object file.
  2550.                 push (@{$lang_specific_files{$lang->name}}, $val);
  2551.             }
  2552.         }
  2553.         elsif ($extension eq $nonansi_obj)
  2554.         {
  2555.             # This is probably the result of a direct suffix rule.
  2556.             # In this case we just accept the rewrite.
  2557.             $object = "$base$extension";
  2558.             $linker = '';
  2559.         }
  2560.         else
  2561.         {
  2562.             # No error message here.  Used to have one, but it was
  2563.             # very unpopular.
  2564.         # FIXME: we could potentially do more processing here,
  2565.         # perhaps treating the new extension as though it were a
  2566.         # new source extension (as above).  This would require
  2567.         # more restructuring than is appropriate right now.
  2568.             next;
  2569.         }
  2570.  
  2571.     err_am "object `$object' created by `$full' and `$object_map{$object}'"
  2572.       if (defined $object_map{$object}
  2573.           && $object_map{$object} ne $full);
  2574.  
  2575.     my $comp_val = (($object =~ /\.lo$/)
  2576.             ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
  2577.     (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
  2578.     if (defined $object_compilation_map{$comp_obj}
  2579.         && $object_compilation_map{$comp_obj} != 0
  2580.         # Only see the error once.
  2581.         && ($object_compilation_map{$comp_obj}
  2582.         != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
  2583.         && $object_compilation_map{$comp_obj} != $comp_val)
  2584.       {
  2585.         err_am "object `$comp_obj' created both with libtool and without";
  2586.       }
  2587.     $object_compilation_map{$comp_obj} |= $comp_val;
  2588.  
  2589.     if (defined $lang)
  2590.     {
  2591.         # Let the language do some special magic if required.
  2592.         $lang->target_hook ($aggregate, $object, $full);
  2593.     }
  2594.  
  2595.     if ($derived_source)
  2596.       {
  2597.         prog_error ($lang->name . " has automatic dependency tracking")
  2598.           if $lang->autodep ne 'no';
  2599.         # Make sure this new source file is handled next.  That will
  2600.         # make it appear to be at the right place in the list.
  2601.         unshift (@files, $object);
  2602.         # Distribute derived sources unless the source they are
  2603.         # derived from is not.
  2604.         &push_dist_common ($object)
  2605.           unless ($topparent =~ /^(?:nobase_)?nodist_/);
  2606.         next;
  2607.       }
  2608.  
  2609.         $linkers_used{$linker} = 1;
  2610.  
  2611.         push (@result, $object);
  2612.  
  2613.         if (! defined $object_map{$object})
  2614.         {
  2615.             my @dep_list = ();
  2616.             $object_map{$object} = $full;
  2617.  
  2618.             # If resulting object is in subdir, we need to make
  2619.             # sure the subdir exists at build time.
  2620.             if ($object =~ /\//)
  2621.             {
  2622.                 # FIXME: check that $DIRECTORY is somewhere in the
  2623.                 # project
  2624.  
  2625.         # For Java, the way we're handling it right now, a
  2626.         # `..' component doesn't make sense.
  2627.                 if ($lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
  2628.           {
  2629.             err_am "`$full' should not contain a `..' component";
  2630.           }
  2631.  
  2632.         # Make sure object is removed by `make mostlyclean'.
  2633.         $compile_clean_files{$object} = MOSTLY_CLEAN;
  2634.         # If we have a libtool object then we also must remove
  2635.         # the ordinary .o.
  2636.         if ($object =~ /\.lo$/)
  2637.         {
  2638.             (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
  2639.             $compile_clean_files{$xobj} = MOSTLY_CLEAN;
  2640.  
  2641.             # Remove any libtool object in this directory.
  2642.             $libtool_clean_directories{$directory} = 1;
  2643.         }
  2644.  
  2645.                 push (@dep_list, require_build_directory ($directory));
  2646.  
  2647.                 # If we're generating dependencies, we also want
  2648.                 # to make sure that the appropriate subdir of the
  2649.                 # .deps directory is created.
  2650.         push (@dep_list,
  2651.               require_build_directory ($directory . '/$(DEPDIR)'))
  2652.             if $use_dependencies;
  2653.             }
  2654.  
  2655.             &pretty_print_rule ($object . ':', "\t", @dep_list)
  2656.                 if scalar @dep_list > 0;
  2657.         }
  2658.  
  2659.         # Transform .o or $o file into .P file (for automatic
  2660.         # dependency code).
  2661.         if ($lang && $lang->autodep ne 'no')
  2662.         {
  2663.             my $depfile = $object;
  2664.             $depfile =~ s/\.([^.]*)$/.P$1/;
  2665.             $depfile =~ s/\$\(OBJEXT\)$/o/;
  2666.             $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
  2667.                . basename ($depfile)} = 1;
  2668.         }
  2669.     }
  2670.  
  2671.     return @result;
  2672. }
  2673.  
  2674. # ($LINKER, $OBJVAR)
  2675. # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
  2676. #                              $OBJ, $PARENT, $TOPPARENT)
  2677. # ---------------------------------------------------------------------
  2678. # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
  2679. #
  2680. # Arguments are:
  2681. #   $VAR is the name of the _SOURCES variable
  2682. #   $OBJVAR is the name of the _OBJECTS variable if known (otherwise
  2683. #     it will be generated and returned).
  2684. #   $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
  2685. #     work done to determine the linker will be).
  2686. #   $ONE_FILE is the canonical (transformed) name of object to build
  2687. #   $OBJ is the object extension (ie either `.o' or `.lo').
  2688. #   $PARENT is the variable in which $VAR is used, or $VAR if not applicable.
  2689. #   $TOPPARENT is the _SOURCES variable being processed.
  2690. #
  2691. # Result is a pair ($LINKER, $OBJVAR):
  2692. #    $LINKER is a boolean, true if a linker is needed to deal with the objects,
  2693. #    $OBJVAR is the name of the variable defined to hold the objects.
  2694. #
  2695. # %linkers_used, %vars_scanned, @substfroms and @substtos should be cleared
  2696. # before use:
  2697. #   %linkers_used variable will be set to contain the linkers desired.
  2698. #   %vars_scanned will be used to check for recursive definitions.
  2699. #   @substfroms and @substtos will be used to keep a stack of variable
  2700. #   substitutions to be applied.
  2701. #
  2702. sub define_objects_from_sources ($$$$$$$)
  2703. {
  2704.     my ($var, $objvar, $nodefine, $one_file, $obj, $parent, $topparent) = @_;
  2705.  
  2706.     if (defined $vars_scanned{$var})
  2707.     {
  2708.     err_var $var, "variable `$var' recursively defined";
  2709.     return "";
  2710.     }
  2711.     $vars_scanned{$var} = 1;
  2712.  
  2713.     my $needlinker = "";
  2714.     my @allresults = ();
  2715.     foreach my $cond (variable_conditions ($var))
  2716.     {
  2717.     my @result;
  2718.     foreach my $val (&variable_value_as_list ($var, $cond, $parent))
  2719.     {
  2720.         # If $val is a variable (i.e. ${foo} or $(bar), not a filename),
  2721.         # handle the sub variable recursively.
  2722.         if ($val =~ /^\$\{([^}]*)\}$/ || $val =~ /^\$\(([^)]*)\)$/)
  2723.         {
  2724.         my $subvar = $1;
  2725.  
  2726.         # If the user uses a losing variable name, just ignore it.
  2727.         # This isn't ideal, but people have requested it.
  2728.         next if ($subvar =~ /\@.*\@/);
  2729.  
  2730.         # See if the variable is actually a substitution reference
  2731.         my ($from, $to);
  2732.         my @temp_list;
  2733.         if ($subvar =~ /$SUBST_REF_PATTERN/o)
  2734.         {
  2735.             $subvar = $1;
  2736.             $to = $3;
  2737.             $from = quotemeta $2;
  2738.         }
  2739.         push @substfroms, $from;
  2740.         push @substtos, $to;
  2741.  
  2742.         my ($temp, $varname)
  2743.             = define_objects_from_sources ($subvar, undef,
  2744.                            $nodefine, $one_file,
  2745.                            $obj, $var, $topparent);
  2746.  
  2747.         push (@result, '$('. $varname . ')');
  2748.         $needlinker ||= $temp;
  2749.  
  2750.         pop @substfroms;
  2751.         pop @substtos;
  2752.         }
  2753.         else # $var is a filename
  2754.         {
  2755.             my $substnum=$#substfroms;
  2756.             while ($substnum >= 0)
  2757.         {
  2758.             $val =~ s/$substfroms[$substnum]$/$substtos[$substnum]/
  2759.             if defined $substfroms[$substnum];
  2760.             $substnum -= 1;
  2761.         }
  2762.  
  2763.         my (@transformed) =
  2764.               &handle_single_transform_list ($var, $topparent, $one_file, $obj, $val);
  2765.         push (@result, @transformed);
  2766.         $needlinker = "true" if @transformed;
  2767.         }
  2768.     }
  2769.     push (@allresults, [$cond, @result]);
  2770.     }
  2771.     # Find a name for the variable, unless imposed.
  2772.     $objvar = subobjname (@allresults) unless defined $objvar;
  2773.     # Define _OBJECTS conditionally
  2774.     unless ($nodefine)
  2775.     {
  2776.     foreach my $pair (@allresults)
  2777.     {
  2778.         my ($cond, @result) = @$pair;
  2779.         define_pretty_variable ($objvar, $cond, @result);
  2780.     }
  2781.     }
  2782.  
  2783.     delete $vars_scanned{$var};
  2784.     return ($needlinker, $objvar);
  2785. }
  2786.  
  2787.  
  2788. # $VARNAME
  2789. # subobjname (@DEFINITIONS)
  2790. # -------------------------
  2791. # Return a name for an object variable that with definitions @DEFINITIONS.
  2792. # @DEFINITIONS is a list of pair [$COND, @OBJECTS].
  2793. #
  2794. # If we already have an object variable containing @DEFINITIONS, reuse it.
  2795. # This way, we avoid combinatorial explosion of the generated
  2796. # variables.  Especially, in a Makefile such as:
  2797. #
  2798. # | if FOO1
  2799. # | A1=1
  2800. # | endif
  2801. # |
  2802. # | if FOO2
  2803. # | A2=2
  2804. # | endif
  2805. # |
  2806. # | ...
  2807. # |
  2808. # | if FOON
  2809. # | AN=N
  2810. # | endif
  2811. # |
  2812. # | B=$(A1) $(A2) ... $(AN)
  2813. # |
  2814. # | c_SOURCES=$(B)
  2815. # | d_SOURCES=$(B)
  2816. #
  2817. # The generated c_OBJECTS and d_OBJECTS will share the same variable
  2818. # definitions.
  2819. #
  2820. # This setup can be the case of a testsuite containing lots (>100) of
  2821. # small C programs, all testing the same set of source files.
  2822. sub subobjname (@)
  2823. {
  2824.     my $key = '';
  2825.     foreach my $pair (@_)
  2826.     {
  2827.     my ($cond, @values) = @$pair;
  2828.     $key .= "($cond)@values";
  2829.     }
  2830.  
  2831.     return $subobjvar{$key} if exists $subobjvar{$key};
  2832.  
  2833.     my $num = 1 + keys (%subobjvar);
  2834.     my $name = "am__objects_${num}";
  2835.     $subobjvar{$key} = $name;
  2836.     return $name;
  2837. }
  2838.  
  2839.  
  2840. # Handle SOURCE->OBJECT transform for one program or library.
  2841. # Arguments are:
  2842. #   canonical (transformed) name of object to build
  2843. #   actual name of object to build
  2844. #   object extension (ie either `.o' or `$o'.
  2845. # Return result is name of linker variable that must be used.
  2846. # Empty return means just use `LINK'.
  2847. sub handle_source_transform
  2848. {
  2849.     # one_file is canonical name.  unxformed is given name.  obj is
  2850.     # object extension.
  2851.     my ($one_file, $unxformed, $obj) = @_;
  2852.  
  2853.     my ($linker) = '';
  2854.  
  2855.     # No point in continuing if _OBJECTS is defined.
  2856.     return if reject_var ($one_file . '_OBJECTS',
  2857.               $one_file . '_OBJECTS should not be defined');
  2858.  
  2859.     my %used_pfx = ();
  2860.     my $needlinker;
  2861.     %linkers_used = ();
  2862.     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
  2863.             'dist_EXTRA_', 'nodist_EXTRA_')
  2864.     {
  2865.     my $var = $prefix . $one_file . "_SOURCES";
  2866.     next
  2867.       if !variable_defined ($var);
  2868.  
  2869.     # We are going to define _OBJECTS variables using the prefix.
  2870.     # Then we glom them all together.  So we can't use the null
  2871.     # prefix here as we need it later.
  2872.     my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
  2873.  
  2874.     # Keep track of which prefixes we saw.
  2875.     $used_pfx{$xpfx} = 1
  2876.       unless $prefix =~ /EXTRA_/;
  2877.  
  2878.     push @sources, "\$($var)";
  2879.     if ($prefix !~ /^nodist_/)
  2880.       {
  2881.         # If the VAR wasn't defined conditionally, we add
  2882.         # it to DIST_SOURCES as is.  Otherwise we create a
  2883.         # am__VAR_DIST variable which contains all possible values,
  2884.         # and add this variable to DIST_SOURCES.
  2885.         my $distvar = "$var";
  2886.         my @conds = variable_conditions_recursive ($var);
  2887.         if (@conds && $conds[0] ne 'TRUE')
  2888.           {
  2889.         $distvar = "am__${var}_DIST";
  2890.         my @files =
  2891.           uniq (variable_value_as_list_recursive ($var, 'all'));
  2892.         define_pretty_variable ($distvar, '', @files);
  2893.           }
  2894.         push @dist_sources, "\$($distvar)"
  2895.       }
  2896.  
  2897.     @substfroms = ();
  2898.     @substtos = ();
  2899.     %vars_scanned = ();
  2900.     my ($temp, $objvar) =
  2901.         define_objects_from_sources ($var,
  2902.                      $xpfx . $one_file . '_OBJECTS',
  2903.                      $prefix =~ /EXTRA_/,
  2904.                      $one_file, $obj, $var, $var);
  2905.     $needlinker ||= $temp;
  2906.     }
  2907.     if ($needlinker)
  2908.     {
  2909.     $linker ||= &resolve_linker (%linkers_used);
  2910.     }
  2911.  
  2912.     my @keys = sort keys %used_pfx;
  2913.     if (scalar @keys == 0)
  2914.     {
  2915.     &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
  2916.     push (@sources, $unxformed . '.c');
  2917.     push (@dist_sources, $unxformed . '.c');
  2918.  
  2919.     %linkers_used = ();
  2920.     my (@result) =
  2921.       &handle_single_transform_list ($one_file . '_SOURCES',
  2922.                      $one_file . '_SOURCES',
  2923.                      $one_file, $obj,
  2924.                      "$unxformed.c");
  2925.     $linker ||= &resolve_linker (%linkers_used);
  2926.     define_pretty_variable ($one_file . "_OBJECTS", '', @result)
  2927.     }
  2928.     else
  2929.     {
  2930.     grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
  2931.     define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
  2932.     }
  2933.  
  2934.     # If we want to use `LINK' we must make sure it is defined.
  2935.     if ($linker eq '')
  2936.     {
  2937.     $need_link = 1;
  2938.     }
  2939.  
  2940.     return $linker;
  2941. }
  2942.  
  2943.  
  2944. # handle_lib_objects ($XNAME, $VAR)
  2945. # ---------------------------------
  2946. # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
  2947. # Also, generate _DEPENDENCIES variable if appropriate.
  2948. # Arguments are:
  2949. #   transformed name of object being built, or empty string if no object
  2950. #   name of _LDADD/_LIBADD-type variable to examine
  2951. # Returns 1 if LIBOBJS seen, 0 otherwise.
  2952. sub handle_lib_objects
  2953. {
  2954.     my ($xname, $var) = @_;
  2955.  
  2956.     prog_error "handle_lib_objects: $var undefined"
  2957.       if ! variable_defined ($var);
  2958.  
  2959.     my $ret = 0;
  2960.     foreach my $cond (variable_conditions_recursive ($var))
  2961.       {
  2962.     if (&handle_lib_objects_cond ($xname, $var, $cond))
  2963.       {
  2964.         $ret = 1;
  2965.       }
  2966.       }
  2967.     return $ret;
  2968. }
  2969.  
  2970. # Subroutine of handle_lib_objects: handle a particular condition.
  2971. sub handle_lib_objects_cond
  2972. {
  2973.     my ($xname, $var, $cond) = @_;
  2974.  
  2975.     # We recognize certain things that are commonly put in LIBADD or
  2976.     # LDADD.
  2977.     my @dep_list = ();
  2978.  
  2979.     my $seen_libobjs = 0;
  2980.     my $flagvar = 0;
  2981.  
  2982.     foreach my $lsearch (&variable_value_as_list_recursive ($var, $cond))
  2983.     {
  2984.     # Skip -lfoo and -Ldir; these are explicitly allowed.
  2985.     next if $lsearch =~ /^-[lL]/;
  2986.     if (! $flagvar && $lsearch =~ /^-/)
  2987.     {
  2988.         if ($var =~ /^(.*)LDADD$/)
  2989.         {
  2990.         # Skip -dlopen and -dlpreopen; these are explicitly allowed.
  2991.         next if $lsearch =~ /^-dl(pre)?open$/;
  2992.         my $prefix = $1 || 'AM_';
  2993.         err_var ($var, "linker flags such as `$lsearch' belong in "
  2994.              . "`${prefix}LDFLAGS");
  2995.         }
  2996.         else
  2997.         {
  2998.         $var =~ /^(.*)LIBADD$/;
  2999.         # Only get this error once.
  3000.         $flagvar = 1;
  3001.         err_var ($var, "linker flags such as `$lsearch' belong in "
  3002.              . "`${1}LDFLAGS");
  3003.         }
  3004.     }
  3005.  
  3006.     # Assume we have a file of some sort, and push it onto the
  3007.     # dependency list.  Autoconf substitutions are not pushed;
  3008.     # rarely is a new dependency substituted into (eg) foo_LDADD
  3009.     # -- but "bad things (eg -lX11) are routinely substituted.
  3010.     # Note that LIBOBJS and ALLOCA are exceptions to this rule,
  3011.     # and handled specially below.
  3012.     push (@dep_list, $lsearch)
  3013.         unless $lsearch =~ /^\@.*\@$/;
  3014.  
  3015.     # Automatically handle LIBOBJS and ALLOCA substitutions.
  3016.     # Basically this means adding entries to dep_files.
  3017.     if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
  3018.     {
  3019.         my $lt = $1 ? $1 : '';
  3020.         my $myobjext = ($1 ? 'l' : '') . 'o';
  3021.  
  3022.         push (@dep_list, $lsearch);
  3023.         $seen_libobjs = 1;
  3024.         if (! keys %libsources
  3025.         && ! variable_defined ($lt . 'LIBOBJS'))
  3026.         {
  3027.             err_var ($var, "\@${lt}LIBOBJS\@ seen but never set in "
  3028.              . "`$configure_ac'");
  3029.         }
  3030.  
  3031.         foreach my $iter (keys %libsources)
  3032.         {
  3033.         if ($iter =~ /\.[cly]$/)
  3034.         {
  3035.             &saw_extension ($&);
  3036.             &saw_extension ('.c');
  3037.         }
  3038.  
  3039.         if ($iter =~ /\.h$/)
  3040.         {
  3041.             require_file_with_macro ($cond, $var, FOREIGN, $iter);
  3042.         }
  3043.         elsif ($iter ne 'alloca.c')
  3044.         {
  3045.             my $rewrite = $iter;
  3046.             $rewrite =~ s/\.c$/.P$myobjext/;
  3047.             $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
  3048.             $rewrite = "^" . quotemeta ($iter) . "\$";
  3049.             # Only require the file if it is not a built source.
  3050.             if (! variable_defined ('BUILT_SOURCES')
  3051.             || ! grep (/$rewrite/,
  3052.                    &variable_value_as_list_recursive (
  3053.                        'BUILT_SOURCES', 'all')))
  3054.             {
  3055.             require_file_with_macro ($cond, $var, FOREIGN, $iter);
  3056.             }
  3057.         }
  3058.         }
  3059.     }
  3060.     elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
  3061.     {
  3062.         my $lt = $1 ? $1 : '';
  3063.         my $myobjext = ($1 ? 'l' : '') . 'o';
  3064.  
  3065.         push (@dep_list, $lsearch);
  3066.         err_var ($var, "\@${lt}ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in "
  3067.              . "`$configure_ac'")
  3068.           if ! defined $libsources{'alloca.c'};
  3069.         $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
  3070.         require_file_with_macro ($cond, $var, FOREIGN, 'alloca.c');
  3071.         &saw_extension ('c');
  3072.     }
  3073.     }
  3074.  
  3075.   if ($xname ne '')
  3076.     {
  3077.       my $depvar = $xname . '_DEPENDENCIES';
  3078.       if ((conditional_ambiguous_p ($depvar, $cond,
  3079.                     keys %{$var_value{$depvar}}))[0] ne '')
  3080.     {
  3081.       # Note that we've examined this.
  3082.       &examine_variable ($depvar);
  3083.     }
  3084.       else
  3085.     {
  3086.       define_pretty_variable ($depvar, $cond, @dep_list);
  3087.     }
  3088.     }
  3089.  
  3090.   return $seen_libobjs;
  3091. }
  3092.  
  3093. # Canonicalize the input parameter
  3094. sub canonicalize
  3095. {
  3096.     my ($string) = @_;
  3097.     $string =~ tr/A-Za-z0-9_\@/_/c;
  3098.     return $string;
  3099. }
  3100.  
  3101. # Canonicalize a name, and check to make sure the non-canonical name
  3102. # is never used.  Returns canonical name.  Arguments are name and a
  3103. # list of suffixes to check for.
  3104. sub check_canonical_spelling
  3105. {
  3106.   my ($name, @suffixes) = @_;
  3107.  
  3108.   my $xname = &canonicalize ($name);
  3109.   if ($xname ne $name)
  3110.     {
  3111.       foreach my $xt (@suffixes)
  3112.     {
  3113.       reject_var ("$name$xt", "use `$xname$xt', not `$name$xt'");
  3114.     }
  3115.     }
  3116.  
  3117.   return $xname;
  3118. }
  3119.  
  3120.  
  3121. # handle_compile ()
  3122. # -----------------
  3123. # Set up the compile suite.
  3124. sub handle_compile ()
  3125. {
  3126.     return
  3127.       unless $get_object_extension_was_run;
  3128.  
  3129.     # Boilerplate.
  3130.     my $default_includes = '';
  3131.     if (! defined $options{'nostdinc'})
  3132.       {
  3133.     $default_includes = ' -I. -I$(srcdir)';
  3134.  
  3135.     if (variable_defined ('CONFIG_HEADER'))
  3136.       {
  3137.         foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
  3138.           {
  3139.         $default_includes .= ' -I' . dirname ($hdr);
  3140.           }
  3141.       }
  3142.       }
  3143.  
  3144.     my (@mostly_rms, @dist_rms);
  3145.     foreach my $item (sort keys %compile_clean_files)
  3146.     {
  3147.     if ($compile_clean_files{$item} == MOSTLY_CLEAN)
  3148.     {
  3149.         push (@mostly_rms, "\t-rm -f $item");
  3150.     }
  3151.     elsif ($compile_clean_files{$item} == DIST_CLEAN)
  3152.     {
  3153.         push (@dist_rms, "\t-rm -f $item");
  3154.     }
  3155.     else
  3156.     {
  3157.       prog_error 'invalid entry in %compile_clean_files';
  3158.     }
  3159.     }
  3160.  
  3161.     my ($coms, $vars, $rules) =
  3162.       &file_contents_internal (1, "$libdir/am/compile.am",
  3163.                    ('DEFAULT_INCLUDES' => $default_includes,
  3164.                 'MOSTLYRMS' => join ("\n", @mostly_rms),
  3165.                 'DISTRMS' => join ("\n", @dist_rms)));
  3166.     $output_vars .= $vars;
  3167.     $output_rules .= "$coms$rules";
  3168.  
  3169.     # Check for automatic de-ANSI-fication.
  3170.     if (defined $options{'ansi2knr'})
  3171.       {
  3172.     my ($ansi2knr_filename, $ansi2knr_where) = @{$options{'ansi2knr'}};
  3173.     my $ansi2knr_dir = '';
  3174.  
  3175.     require_variables ($ansi2knr_where, "option `ansi2knr' is used",
  3176.                'TRUE', "ANSI2KNR", "U");
  3177.  
  3178.     # topdir is where ansi2knr should be.
  3179.     if ($ansi2knr_filename eq 'ansi2knr')
  3180.       {
  3181.         # Only require ansi2knr files if they should appear in
  3182.         # this directory.
  3183.         require_file ($ansi2knr_where, FOREIGN,
  3184.               'ansi2knr.c', 'ansi2knr.1');
  3185.  
  3186.         # ansi2knr needs to be built before subdirs, so unshift it.
  3187.         unshift (@all, '$(ANSI2KNR)');
  3188.       }
  3189.     else
  3190.       {
  3191.         $ansi2knr_dir = dirname ($ansi2knr_filename);
  3192.       }
  3193.  
  3194.     $output_rules .= &file_contents ('ansi2knr',
  3195.                      ('ANSI2KNR-DIR' => $ansi2knr_dir));
  3196.     }
  3197. }
  3198.  
  3199. # handle_libtool ()
  3200. # -----------------
  3201. # Handle libtool rules.
  3202. sub handle_libtool
  3203. {
  3204.   return unless variable_defined ('LIBTOOL');
  3205.  
  3206.   # Libtool requires some files, but only at top level.
  3207.   require_conf_file_with_macro ('TRUE', 'LIBTOOL', FOREIGN, @libtool_files)
  3208.     if $relative_dir eq '.';
  3209.  
  3210.   my @libtool_rms;
  3211.   foreach my $item (sort keys %libtool_clean_directories)
  3212.     {
  3213.       my $dir = ($item eq '.') ? '' : "$item/";
  3214.       # .libs is for Unix, _libs for DOS.
  3215.       push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
  3216.     }
  3217.  
  3218.   # Output the libtool compilation rules.
  3219.   $output_rules .= &file_contents ('libtool',
  3220.                    ('LTRMS' => join ("\n", @libtool_rms)));
  3221. }
  3222.  
  3223. # handle_programs ()
  3224. # ------------------
  3225. # Handle C programs.
  3226. sub handle_programs
  3227. {
  3228.   my @proglist = &am_install_var ('progs', 'PROGRAMS',
  3229.                   'bin', 'sbin', 'libexec', 'pkglib',
  3230.                   'noinst', 'check');
  3231.   return if ! @proglist;
  3232.  
  3233.   my $seen_global_libobjs =
  3234.     variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD');
  3235.  
  3236.   foreach my $one_file (@proglist)
  3237.     {
  3238.       my $seen_libobjs = 0;
  3239.       my $obj = &get_object_extension ($one_file);
  3240.  
  3241.       # Canonicalize names and check for misspellings.
  3242.       my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
  3243.                          '_SOURCES', '_OBJECTS',
  3244.                          '_DEPENDENCIES');
  3245.  
  3246.       my $linker = &handle_source_transform ($xname, $one_file, $obj);
  3247.  
  3248.       my $xt = '';
  3249.       if (variable_defined ($xname . "_LDADD"))
  3250.     {
  3251.       $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
  3252.       $xt = '_LDADD';
  3253.     }
  3254.       else
  3255.     {
  3256.       # User didn't define prog_LDADD override.  So do it.
  3257.       &define_variable ($xname . '_LDADD', '$(LDADD)');
  3258.  
  3259.       # This does a bit too much work.  But we need it to
  3260.       # generate _DEPENDENCIES when appropriate.
  3261.       if (variable_defined ('LDADD'))
  3262.         {
  3263.           $seen_libobjs = &handle_lib_objects ($xname, 'LDADD');
  3264.         }
  3265.       elsif (! variable_defined ($xname . '_DEPENDENCIES'))
  3266.         {
  3267.           &define_variable ($xname . '_DEPENDENCIES', '');
  3268.         }
  3269.       $xt = '_SOURCES';
  3270.     }
  3271.  
  3272.       reject_var ($xname . '_LIBADD',
  3273.           "use `${xname}_LDADD', not `${xname}_LIBADD'");
  3274.  
  3275.       if (! variable_defined ($xname . '_LDFLAGS'))
  3276.     {
  3277.       # Define the prog_LDFLAGS variable.
  3278.       &define_variable ($xname . '_LDFLAGS', '');
  3279.     }
  3280.  
  3281.       # Determine program to use for link.
  3282.       my $xlink;
  3283.       if (variable_defined ($xname . '_LINK'))
  3284.     {
  3285.       $xlink = $xname . '_LINK';
  3286.     }
  3287.       else
  3288.     {
  3289.       $xlink = $linker ? $linker : 'LINK';
  3290.     }
  3291.  
  3292.       # If the resulting program lies into a subdirectory,
  3293.       # make sure this directory will exist.
  3294.       my $dirstamp = require_build_directory_maybe ($one_file);
  3295.  
  3296.       # Don't add $(EXEEXT) if user already did.
  3297.       my $extension = ($one_file !~ /\$\(EXEEXT\)$/
  3298.                ? "\$(EXEEXT)"
  3299.                : '');
  3300.  
  3301.       $output_rules .= &file_contents ('program',
  3302.                        ('PROGRAM'  => $one_file,
  3303.                     'XPROGRAM' => $xname,
  3304.                     'XLINK'    => $xlink,
  3305.                     'DIRSTAMP' => $dirstamp,
  3306.                     'EXEEXT'   => $extension));
  3307.  
  3308.       if ($seen_libobjs || $seen_global_libobjs)
  3309.     {
  3310.       if (variable_defined ($xname . '_LDADD'))
  3311.         {
  3312.           &check_libobjs_sources ($xname, $xname . '_LDADD');
  3313.         }
  3314.       elsif (variable_defined ('LDADD'))
  3315.         {
  3316.           &check_libobjs_sources ($xname, 'LDADD');
  3317.         }
  3318.     }
  3319.     }
  3320. }
  3321.  
  3322.  
  3323. # handle_libraries ()
  3324. # -------------------
  3325. # Handle libraries.
  3326. sub handle_libraries
  3327. {
  3328.   my @liblist = &am_install_var ('libs', 'LIBRARIES',
  3329.                  'lib', 'pkglib', 'noinst', 'check');
  3330.   return if ! @liblist;
  3331.  
  3332.   my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
  3333.                     'noinst', 'check');
  3334.  
  3335.   require_variables_for_macro ($prefix[0] . '_LIBRARIES',
  3336.                    'library used', 'RANLIB')
  3337.     if (@prefix);
  3338.  
  3339.   foreach my $onelib (@liblist)
  3340.     {
  3341.       my $seen_libobjs = 0;
  3342.       # Check that the library fits the standard naming convention.
  3343.       if (basename ($onelib) !~ /^lib.*\.a/)
  3344.     {
  3345.       # FIXME should put line number here.  That means mapping
  3346.       # from library name back to variable name.
  3347.       err_am "`$onelib' is not a standard library name";
  3348.     }
  3349.  
  3350.       my $obj = &get_object_extension ($onelib);
  3351.  
  3352.       # Canonicalize names and check for misspellings.
  3353.       my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
  3354.                         '_OBJECTS', '_DEPENDENCIES',
  3355.                         '_AR');
  3356.  
  3357.       if (! variable_defined ($xlib . '_AR'))
  3358.     {
  3359.       &define_variable ($xlib . '_AR', '$(AR) cru');
  3360.     }
  3361.  
  3362.       if (variable_defined ($xlib . '_LIBADD'))
  3363.     {
  3364.       if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
  3365.         {
  3366.           $seen_libobjs = 1;
  3367.         }
  3368.     }
  3369.       else
  3370.     {
  3371.       # Generate support for conditional object inclusion in
  3372.       # libraries.
  3373.       &define_variable ($xlib . "_LIBADD", '');
  3374.     }
  3375.  
  3376.       reject_var ($xlib . '_LDADD',
  3377.           "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
  3378.  
  3379.       # Make sure we at look at this.
  3380.       &examine_variable ($xlib . '_DEPENDENCIES');
  3381.  
  3382.       &handle_source_transform ($xlib, $onelib, $obj);
  3383.  
  3384.       # If the resulting library lies into a subdirectory,
  3385.       # make sure this directory will exist.
  3386.       my $dirstamp = require_build_directory_maybe ($onelib);
  3387.  
  3388.       $output_rules .= &file_contents ('library',
  3389.                        ('LIBRARY'  => $onelib,
  3390.                     'XLIBRARY' => $xlib,
  3391.                     'DIRSTAMP' => $dirstamp));
  3392.  
  3393.       if ($seen_libobjs)
  3394.     {
  3395.       if (variable_defined ($xlib . '_LIBADD'))
  3396.         {
  3397.           &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
  3398.         }
  3399.     }
  3400.     }
  3401. }
  3402.  
  3403.  
  3404. # handle_ltlibraries ()
  3405. # ---------------------
  3406. # Handle shared libraries.
  3407. sub handle_ltlibraries
  3408. {
  3409.   my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
  3410.                  'noinst', 'lib', 'pkglib', 'check');
  3411.   return if ! @liblist;
  3412.  
  3413.   my %instdirs;
  3414.   my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
  3415.                     'noinst', 'check');
  3416.  
  3417.   require_variables_for_macro ($prefix[0] . '_LTLIBRARIES',
  3418.                    'Libtool library used', 'LIBTOOL')
  3419.     if (@prefix);
  3420.  
  3421.   foreach my $key (@prefix)
  3422.     {
  3423.       # Get the installation directory of each library.
  3424.       (my $dir = $key) =~ s/^nobase_//;
  3425.       for (variable_value_as_list_recursive ($key . '_LTLIBRARIES', 'all'))
  3426.     {
  3427.       # We reject libraries which are installed in several places,
  3428.       # because we don't handle this in the rules (think `-rpath').
  3429.       #
  3430.       # However, we allow the same library to be listed many times
  3431.       # for the same directory.  This is for users who need setups
  3432.       # like
  3433.       #   if COND1
  3434.       #     lib_LTLIBRARIES = libfoo.la
  3435.       #   endif
  3436.       #   if COND2
  3437.       #     lib_LTLIBRARIES = libfoo.la
  3438.       #   endif
  3439.       #
  3440.       # Actually this will also allow
  3441.       #   lib_LTLIBRARIES = libfoo.la libfoo.la
  3442.       # Diagnosing this case doesn't seem worth the plain (we'd
  3443.       # have to fill $instdirs on a per-condition basis, check
  3444.       # implied conditions, etc.)
  3445.       if (defined $instdirs{$_} && $instdirs{$_} ne $dir)
  3446.         {
  3447.           err_am ("`$_' is already going to be installed in "
  3448.               . "`$instdirs{$_}'");
  3449.         }
  3450.       else
  3451.         {
  3452.           $instdirs{$_} = $dir;
  3453.         }
  3454.     }
  3455.     }
  3456.  
  3457.   foreach my $onelib (@liblist)
  3458.     {
  3459.       my $seen_libobjs = 0;
  3460.       my $obj = &get_object_extension ($onelib);
  3461.  
  3462.       # Canonicalize names and check for misspellings.
  3463.       my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
  3464.                         '_SOURCES', '_OBJECTS',
  3465.                         '_DEPENDENCIES');
  3466.  
  3467.       my $ldflags = $xlib . '_LDFLAGS';
  3468.       if (! variable_defined ($xlib . '_LDFLAGS'))
  3469.     {
  3470.       # Define the lib_LDFLAGS variable.
  3471.       &define_variable ($xlib . '_LDFLAGS', '');
  3472.       $ldflags = 'AM_LDFLAGS'
  3473.     }
  3474.  
  3475.       # Check that the library fits the standard naming convention.
  3476.       my $libname_rx = "^lib.*\.la";
  3477.       if ((variable_defined ($ldflags)
  3478.        && grep (/-module/,
  3479.             &variable_value_as_list_recursive ($ldflags, 'all')))
  3480.       || (variable_defined ('LDFLAGS')
  3481.           && grep (/-module/,
  3482.                &variable_value_as_list_recursive ('LDFLAGS', 'all'))))
  3483.     {
  3484.       # Relax name checking for libtool modules.
  3485.       $libname_rx = "\.la";
  3486.     }
  3487.       if (basename ($onelib) !~ /$libname_rx$/)
  3488.     {
  3489.       # FIXME should put line number here.  That means mapping
  3490.       # from library name back to variable name.
  3491.       msg_am ('error-gnu/warn',
  3492.           "`$onelib' is not a standard libtool library name");
  3493.     }
  3494.  
  3495.       if (variable_defined ($xlib . '_LIBADD'))
  3496.     {
  3497.       if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
  3498.         {
  3499.           $seen_libobjs = 1;
  3500.         }
  3501.     }
  3502.       else
  3503.     {
  3504.       # Generate support for conditional object inclusion in
  3505.       # libraries.
  3506.       &define_variable ($xlib . "_LIBADD", '');
  3507.     }
  3508.  
  3509.       reject_var ("${xlib}_LDADD",
  3510.           "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
  3511.  
  3512.       # Make sure we at look at this.
  3513.       &examine_variable ($xlib . '_DEPENDENCIES');
  3514.  
  3515.       my $linker = &handle_source_transform ($xlib, $onelib, $obj);
  3516.  
  3517.       # Determine program to use for link.
  3518.       my $xlink;
  3519.       if (variable_defined ($xlib . '_LINK'))
  3520.     {
  3521.       $xlink = $xlib . '_LINK';
  3522.     }
  3523.       else
  3524.     {
  3525.       $xlink = $linker ? $linker : 'LINK';
  3526.     }
  3527.  
  3528.       my $rpath;
  3529.       if ($instdirs{$onelib} eq 'EXTRA'
  3530.       || $instdirs{$onelib} eq 'noinst'
  3531.       || $instdirs{$onelib} eq 'check')
  3532.     {
  3533.       # It's an EXTRA_ library, so we can't specify -rpath,
  3534.       # because we don't know where the library will end up.
  3535.       # The user probably knows, but generally speaking automake
  3536.       # doesn't -- and in fact configure could decide
  3537.       # dynamically between two different locations.
  3538.       $rpath = '';
  3539.     }
  3540.       else
  3541.     {
  3542.       $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
  3543.     }
  3544.  
  3545.       # If the resulting library lies into a subdirectory,
  3546.       # make sure this directory will exist.
  3547.       my $dirstamp = require_build_directory_maybe ($onelib);
  3548.  
  3549.       # Remember to cleanup .libs/ in this directory.
  3550.       my $dirname = dirname $onelib;
  3551.       $libtool_clean_directories{$dirname} = 1;
  3552.  
  3553.       $output_rules .= &file_contents ('ltlibrary',
  3554.                        ('LTLIBRARY'  => $onelib,
  3555.                     'XLTLIBRARY' => $xlib,
  3556.                     'RPATH'      => $rpath,
  3557.                     'XLINK'      => $xlink,
  3558.                     'DIRSTAMP'   => $dirstamp));
  3559.       if ($seen_libobjs)
  3560.     {
  3561.       if (variable_defined ($xlib . '_LIBADD'))
  3562.         {
  3563.           &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
  3564.         }
  3565.     }
  3566.     }
  3567. }
  3568.  
  3569. # See if any _SOURCES variable were misspelled.
  3570. sub check_typos ()
  3571. {
  3572.   # It is ok if the user sets this particular variable.
  3573.   &examine_variable ('AM_LDFLAGS');
  3574.  
  3575.   foreach my $varname (keys %var_value)
  3576.     {
  3577.       foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
  3578.                '_DEPENDENCIES')
  3579.     {
  3580.       msg_var 'syntax', $varname, "unused variable: `$varname'"
  3581.         # Note that a configure variable is always legitimate.
  3582.         if ($varname =~ /$primary$/ && ! $content_seen{$varname}
  3583.         && ! exists $configure_vars{$varname});
  3584.     }
  3585.     }
  3586. }
  3587.  
  3588.  
  3589. # Handle scripts.
  3590. sub handle_scripts
  3591. {
  3592.     # NOTE we no longer automatically clean SCRIPTS, because it is
  3593.     # useful to sometimes distribute scripts verbatim.  This happens
  3594.     # eg in Automake itself.
  3595.     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
  3596.              'bin', 'sbin', 'libexec', 'pkgdata',
  3597.              'noinst', 'check');
  3598. }
  3599.  
  3600.  
  3601. # ($OUTFILE, $VFILE, @CLEAN_FILES)
  3602. # &scan_texinfo_file ($FILENAME)
  3603. # ------------------------------
  3604. # $OUTFILE is the name of the info file produced by $FILENAME.
  3605. # $VFILE is the name of the version.texi file used (empty if none).
  3606. # @CLEAN_FILES is the list of by products (indexes etc.)
  3607. sub scan_texinfo_file
  3608. {
  3609.     my ($filename) = @_;
  3610.  
  3611.     # Some of the following extensions are always created, no matter
  3612.     # whether indexes are used or not.  Other (like cps, fns, ... pgs)
  3613.     # are only created when they are used.  We used to scan $FILENAME
  3614.     # for their use, but that is not enough: they could be used in
  3615.     # included files.  We can't scan included files because we don't
  3616.     # know the include path.  Therefore we always erase these files,
  3617.     # no matter whether they are used or not.
  3618.     #
  3619.     # (tmp is only created if an @macro is used and a certain e-TeX
  3620.     # feature is not available.)
  3621.     my %clean_suffixes =
  3622.       map { $_ => 1 } (qw(aux log toc tmp
  3623.               cp cps
  3624.               fn fns
  3625.               ky kys
  3626.               vr vrs
  3627.               tp tps
  3628.               pg pgs)); # grep 'new.*index' texinfo.tex
  3629.  
  3630.     my $texi = new Automake::XFile "< $filename";
  3631.     verb "reading $filename";
  3632.  
  3633.     my ($outfile, $vfile);
  3634.     while ($_ = $texi->getline)
  3635.     {
  3636.       if (/^\@setfilename +(\S+)/)
  3637.       {
  3638.     # Honor only the first @setfilename.  (It's possible to have
  3639.     # more occurrences later if the manual shows examples of how
  3640.     # to use @setfilename...)
  3641.     next if $outfile;
  3642.  
  3643.         $outfile = $1;
  3644.         if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
  3645.           {
  3646.         error ("$filename:$.",
  3647.            "output `$outfile' has unrecognized extension");
  3648.             return;
  3649.           }
  3650.       }
  3651.       # A "version.texi" file is actually any file whose name
  3652.       # matches "vers*.texi".
  3653.       elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
  3654.       {
  3655.         $vfile = $1;
  3656.       }
  3657.  
  3658.       # Try to find new or unused indexes.
  3659.  
  3660.       # Creating a new category of index.
  3661.       elsif (/^\@def(code)?index (\w+)/)
  3662.       {
  3663.     $clean_suffixes{$2} = 1;
  3664.     $clean_suffixes{"$2s"} = 1;
  3665.       }
  3666.  
  3667.       # Merging an index into an another.
  3668.       elsif (/^\@syn(code)?index (\w+) (\w+)/)
  3669.       {
  3670.     delete $clean_suffixes{"$2s"};
  3671.     $clean_suffixes{"$3s"} = 1;
  3672.       }
  3673.  
  3674.     }
  3675.  
  3676.     if ($outfile eq '')
  3677.       {
  3678.     err_am "`$filename' missing \@setfilename";
  3679.     return;
  3680.       }
  3681.  
  3682.     my $infobase = basename ($filename);
  3683.     $infobase =~ s/\.te?xi(nfo)?$//;
  3684.     return ($outfile, $vfile,
  3685.         map { "$infobase.$_" } (sort keys %clean_suffixes));
  3686. }
  3687.  
  3688. # ($DIRSTAMP, @CLEAN_FILES)
  3689. # output_texinfo_build_rules ($SOURCE, $DEST, @DEPENDENCIES)
  3690. # ----------------------------------------------------------
  3691. # SOURCE - the source Texinfo file
  3692. # DEST - the destination Info file
  3693. # DEPENDENCIES - known dependencies
  3694. sub output_texinfo_build_rules ($$@)
  3695. {
  3696.   my ($source, $dest, @deps) = @_;
  3697.  
  3698.   # Split `a.texi' into `a' and `.texi'.
  3699.   my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
  3700.   my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
  3701.  
  3702.   $ssfx ||= "";
  3703.   $dsfx ||= "";
  3704.  
  3705.   # We can output two kinds of rules: the "generic" rules
  3706.   # use Make suffix rules and are appropriate when
  3707.   # $source and $dest lie in the current directory; the "specific"
  3708.   # rules are needed in the other case.
  3709.   #
  3710.   # The former are output only once (this is not really apparent
  3711.   # here, but just remember that some logic deeper in Automake will
  3712.   # not output the same rule twice); while the later need to be output
  3713.   # for each Texinfo source.
  3714.   my $generic;
  3715.   my $makeinfoflags;
  3716.   my $sdir = dirname $source;
  3717.   if ($sdir eq '.' && dirname ($dest) eq '.')
  3718.     {
  3719.       $generic = 1;
  3720.       $makeinfoflags = '-I $(srcdir)';
  3721.     }
  3722.   else
  3723.     {
  3724.       $generic = 0;
  3725.       $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
  3726.     }
  3727.  
  3728.   # We cannot use a suffix rule to build info files with
  3729.   # an empty extension.  Otherwise we would output a single suffix
  3730.   # inference rule, with separate dependencies, as in
  3731.   #    .texi:
  3732.   #           $(MAKEINFO) ...
  3733.   #    foo.info: foo.texi
  3734.   # which confuse Solaris make.  (See the Autoconf manual for details.)
  3735.   # Therefore we use a specific rule in this case.  This applies
  3736.   # to info files only (dvi and pdf files always have an extension).
  3737.   my $generic_info = ($generic && $dsfx) ? 1 : 0;
  3738.  
  3739.   # If the resulting file lie into a subdirectory,
  3740.   # make sure this directory will exist.
  3741.   my $dirstamp = require_build_directory_maybe ($dest);
  3742.  
  3743.   $output_rules .= &file_contents ('texibuild',
  3744.                                    GENERIC       => $generic,
  3745.                                    GENERIC_INFO  => $generic_info,
  3746.                                    SOURCE_SUFFIX => $ssfx,
  3747.                                    SOURCE => ($generic ? '$<' : $source),
  3748.                                    SOURCE_INFO   => ($generic_info ?
  3749.                              '$<' : $source),
  3750.                                    SOURCE_REAL   => $source,
  3751.                                    DEST_PREFIX   => $dpfx,
  3752.                                    DEST_SUFFIX   => $dsfx,
  3753.                                    MAKEINFOFLAGS => $makeinfoflags,
  3754.                                    DEPS          => "@deps",
  3755.                    DIRSTAMP      => $dirstamp);
  3756.   return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps");
  3757. }
  3758.  
  3759.  
  3760. # ($DO-SOMETHING, $TEXICLEANS)
  3761. # handle_texinfo_helper ()
  3762. # ------------------------
  3763. # Handle all Texinfo source; helper for handle_texinfo
  3764. sub handle_texinfo_helper
  3765. {
  3766.     reject_var 'TEXINFOS', "`TEXINFOS' is an anachronism; use `info_TEXINFOS'";
  3767.     reject_var 'html_TEXINFOS', "HTML generation not yet supported";
  3768.  
  3769.     return (0, '') if ! variable_defined ('info_TEXINFOS');
  3770.  
  3771.     my @texis = &variable_value_as_list_recursive ('info_TEXINFOS', 'all');
  3772.  
  3773.     my (@info_deps_list, @dvis_list, @pdfs_list, @pss_list, @texi_deps);
  3774.     my %versions;
  3775.     my $done = 0;
  3776.     my @texi_cleans;
  3777.     my $canonical;
  3778.  
  3779.     foreach my $info_cursor (@texis)
  3780.     {
  3781.         my $infobase = $info_cursor;
  3782.         $infobase =~ s/\.(txi|texinfo|texi)$//;
  3783.  
  3784.     if ($infobase eq $info_cursor)
  3785.       {
  3786.         # FIXME: report line number.
  3787.         err_am "texinfo file `$info_cursor' has unrecognized extension";
  3788.         next;
  3789.       }
  3790.  
  3791.     # If 'version.texi' is referenced by input file, then include
  3792.     # automatic versioning capability.
  3793.     my ($out_file, $vtexi, @clean_files) =
  3794.       &scan_texinfo_file ("$relative_dir/$info_cursor")
  3795.         or next;
  3796.     push (@texi_cleans, @clean_files);
  3797.  
  3798.     # If the Texinfo source is in a subdirectory, create the
  3799.     # resulting info in this subdirectory.  If it is in the
  3800.     # current directory, try hard to not prefix "./" because
  3801.     # it breaks the generic rules.
  3802.     my $outdir = dirname ($info_cursor) . '/';
  3803.     $outdir = "" if $outdir eq './';
  3804.     $out_file =  $outdir . $out_file;
  3805.  
  3806.     # If user specified file_TEXINFOS, then use that as explicit
  3807.     # dependency list.
  3808.     @texi_deps = ();
  3809.     push (@texi_deps, "$outdir$vtexi") if $vtexi;
  3810.  
  3811.     my $canonical = &canonicalize ($infobase);
  3812.     if (variable_defined ($canonical . "_TEXINFOS"))
  3813.     {
  3814.         push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
  3815.         &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
  3816.     }
  3817.  
  3818.     my ($dirstamp, @cfiles) =
  3819.       output_texinfo_build_rules ($info_cursor, $out_file, @texi_deps);
  3820.     push (@texi_cleans, @cfiles);
  3821.  
  3822.     push (@info_deps_list, $out_file);
  3823.     push (@dvis_list, $infobase . '.dvi');
  3824.     push (@pdfs_list, $infobase . '.pdf');
  3825.     push (@pss_list, $infobase . '.ps');
  3826.  
  3827.     # If a vers*.texi file is needed, emit the rule.
  3828.     if ($vtexi)
  3829.     {
  3830.         err_am ("`$vtexi', included in `$info_cursor', "
  3831.             . "also included in `$versions{$vtexi}'")
  3832.           if defined $versions{$vtexi};
  3833.         $versions{$vtexi} = $info_cursor;
  3834.  
  3835.         # We number the stamp-vti files.  This is doable since the
  3836.         # actual names don't matter much.  We only number starting
  3837.         # with the second one, so that the common case looks nice.
  3838.         my $vti = ($done ? $done : 'vti');
  3839.         ++$done;
  3840.  
  3841.         # This is ugly, but it is our historical practice.
  3842.         if ($config_aux_dir_set_in_configure_in)
  3843.         {
  3844.         require_conf_file_with_macro ('TRUE', 'info_TEXINFOS', FOREIGN,
  3845.                           'mdate-sh');
  3846.         }
  3847.         else
  3848.         {
  3849.         require_file_with_macro ('TRUE', 'info_TEXINFOS',
  3850.                      FOREIGN, 'mdate-sh');
  3851.         }
  3852.  
  3853.         my $conf_dir;
  3854.         if ($config_aux_dir_set_in_configure_in)
  3855.         {
  3856.         $conf_dir = $config_aux_dir;
  3857.         $conf_dir .= '/' unless $conf_dir =~ /\/$/;
  3858.         }
  3859.         else
  3860.         {
  3861.         $conf_dir = '$(srcdir)/';
  3862.         }
  3863.         $output_rules .= &file_contents ('texi-vers',
  3864.                          TEXI     => $info_cursor,
  3865.                          VTI      => $vti,
  3866.                          STAMPVTI => "${outdir}stamp-$vti",
  3867.                          VTEXI    => "$outdir$vtexi",
  3868.                          MDDIR    => $conf_dir,
  3869.                          DIRSTAMP => $dirstamp);
  3870.     }
  3871.     }
  3872.  
  3873.     # Handle location of texinfo.tex.
  3874.     my $need_texi_file = 0;
  3875.     my $texinfodir;
  3876.     if (variable_defined ('TEXINFO_TEX'))
  3877.     {
  3878.     # The user defined TEXINFO_TEX so assume he knows what he is
  3879.     # doing.
  3880.         $texinfodir = ('$(srcdir)/'
  3881.                . dirname (&variable_value ('TEXINFO_TEX')));
  3882.     }
  3883.     elsif ($cygnus_mode)
  3884.     {
  3885.         $texinfodir = '$(top_srcdir)/../texinfo';
  3886.     &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
  3887.     }
  3888.     elsif ($config_aux_dir_set_in_configure_in)
  3889.     {
  3890.         $texinfodir = $config_aux_dir;
  3891.     &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
  3892.     $need_texi_file = 2; # so that we require_conf_file later
  3893.     }
  3894.     else
  3895.     {
  3896.         $texinfodir = '$(srcdir)';
  3897.     $need_texi_file = 1;
  3898.     }
  3899.     &define_variable ('am__TEXINFO_TEX_DIR', $texinfodir);
  3900.  
  3901.     # The return value.
  3902.     my $texiclean = &pretty_print_internal ("", "\t  ", @texi_cleans);
  3903.  
  3904.     push (@dist_targets, 'dist-info');
  3905.  
  3906.     if (! defined $options{'no-installinfo'})
  3907.     {
  3908.     # Make sure documentation is made and installed first.  Use
  3909.     # $(INFO_DEPS), not 'info', because otherwise recursive makes
  3910.     # get run twice during "make all".
  3911.     unshift (@all, '$(INFO_DEPS)');
  3912.     }
  3913.  
  3914.     &define_variable ("INFO_DEPS", "@info_deps_list");
  3915.     &define_variable ("DVIS", "@dvis_list");
  3916.     &define_variable ("PDFS", "@pdfs_list");
  3917.     &define_variable ("PSS", "@pss_list");
  3918.     # This next isn't strictly needed now -- the places that look here
  3919.     # could easily be changed to look in info_TEXINFOS.  But this is
  3920.     # probably better, in case noinst_TEXINFOS is ever supported.
  3921.     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
  3922.  
  3923.     # Do some error checking.  Note that this file is not required
  3924.     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
  3925.     # up above.
  3926.     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
  3927.     {
  3928.     if ($need_texi_file > 1)
  3929.     {
  3930.         require_conf_file_with_macro ('TRUE', 'info_TEXINFOS', FOREIGN,
  3931.                       'texinfo.tex');
  3932.     }
  3933.     else
  3934.     {
  3935.         require_file_with_macro ('TRUE', 'info_TEXINFOS', FOREIGN,
  3936.                      'texinfo.tex');
  3937.     }
  3938.     }
  3939.  
  3940.     return (1, $texiclean);
  3941. }
  3942.  
  3943. # handle_texinfo ()
  3944. # -----------------
  3945. # Handle all Texinfo source.
  3946. sub handle_texinfo
  3947. {
  3948.     my ($do_something, $texiclean) = handle_texinfo_helper ();
  3949.     $output_rules .=  &file_contents ('texinfos',
  3950.                       ('TEXICLEAN' => $texiclean,
  3951.                        'LOCAL-TEXIS' => $do_something));
  3952. }
  3953.  
  3954. # Handle any man pages.
  3955. sub handle_man_pages
  3956. {
  3957.     reject_var 'MANS', "`MANS' is an anachronism; use `man_MANS'";
  3958.  
  3959.     # Find all the sections in use.  We do this by first looking for
  3960.     # "standard" sections, and then looking for any additional
  3961.     # sections used in man_MANS.
  3962.     my (%sections, %vlist);
  3963.     # We handle nodist_ for uniformity.  man pages aren't distributed
  3964.     # by default so it isn't actually very important.
  3965.     foreach my $pfx ('', 'dist_', 'nodist_')
  3966.     {
  3967.     # Add more sections as needed.
  3968.     foreach my $section ('0'..'9', 'n', 'l')
  3969.     {
  3970.         if (variable_defined ($pfx . 'man' . $section . '_MANS'))
  3971.         {
  3972.         $sections{$section} = 1;
  3973.         $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
  3974.  
  3975.         &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
  3976.             if $pfx eq 'dist_';
  3977.         }
  3978.     }
  3979.  
  3980.     if (variable_defined ($pfx . 'man_MANS'))
  3981.     {
  3982.         $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
  3983.         foreach (&variable_value_as_list_recursive ($pfx . 'man_MANS', 'all'))
  3984.         {
  3985.         # A page like `foo.1c' goes into man1dir.
  3986.         if (/\.([0-9a-z])([a-z]*)$/)
  3987.         {
  3988.             $sections{$1} = 1;
  3989.         }
  3990.         }
  3991.  
  3992.         &push_dist_common ('$(' . $pfx . 'man_MANS)')
  3993.         if $pfx eq 'dist_';
  3994.     }
  3995.     }
  3996.  
  3997.     return unless %sections;
  3998.  
  3999.     # Now for each section, generate an install and uninstall rule.
  4000.     # Sort sections so output is deterministic.
  4001.     foreach my $section (sort keys %sections)
  4002.     {
  4003.     $output_rules .= &file_contents ('mans', ('SECTION' => $section));
  4004.     }
  4005.  
  4006.     my @mans = sort keys %vlist;
  4007.     $output_vars .= file_contents ('mans-vars',
  4008.                    ('MANS' => "@mans"));
  4009.  
  4010.     if (! defined $options{'no-installman'})
  4011.     {
  4012.     push (@all, '$(MANS)');
  4013.     }
  4014. }
  4015.  
  4016. # Handle DATA variables.
  4017. sub handle_data
  4018. {
  4019.     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
  4020.              'data', 'sysconf', 'sharedstate', 'localstate',
  4021.              'pkgdata', 'noinst', 'check');
  4022. }
  4023.  
  4024. # Handle TAGS.
  4025. sub handle_tags
  4026. {
  4027.     my @tag_deps = ();
  4028.     my @ctag_deps = ();
  4029.     if (variable_defined ('SUBDIRS'))
  4030.     {
  4031.     $output_rules .= ("tags-recursive:\n"
  4032.               . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
  4033.               # Never fail here if a subdir fails; it
  4034.               # isn't important.
  4035.               . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
  4036.               . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
  4037.               . "\tdone\n");
  4038.     push (@tag_deps, 'tags-recursive');
  4039.     &depend ('.PHONY', 'tags-recursive');
  4040.  
  4041.     $output_rules .= ("ctags-recursive:\n"
  4042.               . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
  4043.               # Never fail here if a subdir fails; it
  4044.               # isn't important.
  4045.               . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
  4046.               . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
  4047.               . "\tdone\n");
  4048.     push (@ctag_deps, 'ctags-recursive');
  4049.     &depend ('.PHONY', 'ctags-recursive');
  4050.     }
  4051.  
  4052.     if (&saw_sources_p (1)
  4053.     || variable_defined ('ETAGS_ARGS')
  4054.     || @tag_deps)
  4055.     {
  4056.     my @config;
  4057.     foreach my $spec (@config_headers)
  4058.     {
  4059.         my ($out, @ins) = split_config_file_spec ($spec);
  4060.         foreach my $in (@ins)
  4061.           {
  4062.         # If the config header source is in this directory,
  4063.         # require it.
  4064.         push @config, basename ($in)
  4065.           if $relative_dir eq dirname ($in);
  4066.           }
  4067.     }
  4068.     $output_rules .= &file_contents ('tags',
  4069.                      ('CONFIG' => "@config",
  4070.                       'TAGSDIRS'   => "@tag_deps",
  4071.                       'CTAGSDIRS'  => "@ctag_deps"));
  4072.     &examine_variable ('TAGS_DEPENDENCIES');
  4073.     }
  4074.     elsif (reject_var ('TAGS_DEPENDENCIES',
  4075.                "doesn't make sense to define `TAGS_DEPENDENCIES'"
  4076.                . "without\nsources or `ETAGS_ARGS'"))
  4077.     {
  4078.     }
  4079.     else
  4080.     {
  4081.     # Every Makefile must define some sort of TAGS rule.
  4082.     # Otherwise, it would be possible for a top-level "make TAGS"
  4083.     # to fail because some subdirectory failed.
  4084.     $output_rules .= "tags: TAGS\nTAGS:\n\n";
  4085.     # Ditto ctags.
  4086.     $output_rules .= "ctags: CTAGS\nCTAGS:\n\n";
  4087.     }
  4088. }
  4089.  
  4090. # Handle multilib support.
  4091. sub handle_multilib
  4092. {
  4093.     if ($seen_multilib && $relative_dir eq '.')
  4094.     {
  4095.     $output_rules .= &file_contents ('multilib');
  4096.     push (@all, 'all-multi');
  4097.     }
  4098. }
  4099.  
  4100.  
  4101. # $BOOLEAN
  4102. # &for_dist_common ($A, $B)
  4103. # -------------------------
  4104. # Subroutine for &handle_dist: sort files to dist.
  4105. #
  4106. # We put README first because it then becomes easier to make a
  4107. # Usenet-compliant shar file (in these, README must be first).
  4108. #
  4109. # FIXME: do more ordering of files here.
  4110. sub for_dist_common
  4111. {
  4112.     return 0
  4113.         if $a eq $b;
  4114.     return -1
  4115.         if $a eq 'README';
  4116.     return 1
  4117.         if $b eq 'README';
  4118.     return $a cmp $b;
  4119. }
  4120.  
  4121.  
  4122. # handle_dist ($MAKEFILE)
  4123. # -----------------------
  4124. # Handle 'dist' target.
  4125. sub handle_dist
  4126. {
  4127.     my ($makefile) = @_;
  4128.  
  4129.     # `make dist' isn't used in a Cygnus-style tree.
  4130.     # Omit the rules so that people don't try to use them.
  4131.     return if $cygnus_mode;
  4132.  
  4133.     # Look for common files that should be included in distribution.
  4134.     # If the aux dir is set, and it does not have a Makefile.am, then
  4135.     # we check for these files there as well.
  4136.     my $check_aux = 0;
  4137.     my $auxdir = '';
  4138.     if ($relative_dir eq '.'
  4139.     && $config_aux_dir_set_in_configure_in)
  4140.     {
  4141.     ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
  4142.     if (! &is_make_dir ($auxdir))
  4143.     {
  4144.         $check_aux = 1;
  4145.     }
  4146.     }
  4147.     foreach my $cfile (@common_files)
  4148.     {
  4149.     if (-f ($relative_dir . "/" . $cfile)
  4150.         # The file might be absent, but if it can be built it's ok.
  4151.         || exists $targets{$cfile})
  4152.     {
  4153.         &push_dist_common ($cfile);
  4154.     }
  4155.  
  4156.     # Don't use `elsif' here because a file might meaningfully
  4157.     # appear in both directories.
  4158.     if ($check_aux && -f ($auxdir . '/' . $cfile))
  4159.     {
  4160.         &push_dist_common ($auxdir . '/' . $cfile);
  4161.     }
  4162.     }
  4163.  
  4164.     # We might copy elements from $configure_dist_common to
  4165.     # %dist_common if we think we need to.  If the file appears in our
  4166.     # directory, we would have discovered it already, so we don't
  4167.     # check that.  But if the file is in a subdir without a Makefile,
  4168.     # we want to distribute it here if we are doing `.'.  Ugly!
  4169.     if ($relative_dir eq '.')
  4170.     {
  4171.        foreach my $file (split (' ' , $configure_dist_common))
  4172.        {
  4173.        push_dist_common ($file)
  4174.          unless is_make_dir (dirname ($file));
  4175.        }
  4176.     }
  4177.  
  4178.  
  4179.  
  4180.     # Files to distributed.  Don't use &variable_value_as_list_recursive
  4181.     # as it recursively expands `$(dist_pkgdata_DATA)' etc.
  4182.     check_variable_defined_unconditionally ('DIST_COMMON');
  4183.     my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
  4184.     @dist_common = uniq (sort for_dist_common (@dist_common));
  4185.     pretty_print ('DIST_COMMON = ', "\t", @dist_common);
  4186.  
  4187.     # Now that we've processed DIST_COMMON, disallow further attempts
  4188.     # to set it.
  4189.     $handle_dist_run = 1;
  4190.  
  4191.     # Scan EXTRA_DIST to see if we need to distribute anything from a
  4192.     # subdir.  If so, add it to the list.  I didn't want to do this
  4193.     # originally, but there were so many requests that I finally
  4194.     # relented.
  4195.     if (variable_defined ('EXTRA_DIST'))
  4196.     {
  4197.     # FIXME: This should be fixed to work with conditionals.  That
  4198.     # will require only making the entries in %dist_dirs under the
  4199.     # appropriate condition.  This is meaningful if the nature of
  4200.     # the distribution should depend upon the configure options
  4201.     # used.
  4202.     foreach (&variable_value_as_list_recursive ('EXTRA_DIST', ''))
  4203.     {
  4204.         next if /^\@.*\@$/;
  4205.         next unless s,/+[^/]+$,,;
  4206.         $dist_dirs{$_} = 1
  4207.         unless $_ eq '.';
  4208.     }
  4209.     }
  4210.  
  4211.     # We have to check DIST_COMMON for extra directories in case the
  4212.     # user put a source used in AC_OUTPUT into a subdir.
  4213.     my $topsrcdir = backname ($relative_dir);
  4214.     foreach (&variable_value_as_list_recursive ('DIST_COMMON', 'all'))
  4215.     {
  4216.     next if /^\@.*\@$/;
  4217.     s/\$\(top_srcdir\)/$topsrcdir/;
  4218.     s/\$\(srcdir\)/./;
  4219.     next unless s,/+[^/]+$,,;
  4220.     $dist_dirs{$_} = 1
  4221.         unless $_ eq '.';
  4222.     }
  4223.  
  4224.     # Rule to check whether a distribution is viable.
  4225.     my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
  4226.              'GETTEXT' => $seen_gettext && !$seen_gettext_external);
  4227.  
  4228.     # Prepend $(distdir) to each directory given.
  4229.     my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
  4230.     $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
  4231.  
  4232.     # If we have SUBDIRS, create all dist subdirectories and do
  4233.     # recursive build.
  4234.     if (variable_defined ('SUBDIRS'))
  4235.     {
  4236.     # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
  4237.     # to all possible directories, and use it.  If DIST_SUBDIRS is
  4238.     # defined, just use it.
  4239.     my $dist_subdir_name;
  4240.     # Note that we check DIST_SUBDIRS first on purpose.  At least
  4241.     # one project uses so many conditional subdirectories that
  4242.     # calling variable_conditionally_defined on SUBDIRS will cause
  4243.     # automake to grow to 150Mb.  Sigh.
  4244.     if (variable_defined ('DIST_SUBDIRS')
  4245.         || variable_conditionally_defined ('SUBDIRS'))
  4246.     {
  4247.         $dist_subdir_name = 'DIST_SUBDIRS';
  4248.         if (! variable_defined ('DIST_SUBDIRS'))
  4249.         {
  4250.         define_pretty_variable
  4251.           ('DIST_SUBDIRS', '',
  4252.            uniq (&variable_value_as_list_recursive ('SUBDIRS', 'all')));
  4253.         }
  4254.     }
  4255.     else
  4256.     {
  4257.         $dist_subdir_name = 'SUBDIRS';
  4258.         # We always define this because that is what `distclean'
  4259.         # wants.
  4260.         define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
  4261.     }
  4262.  
  4263.     $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
  4264.     }
  4265.  
  4266.     # If the target `dist-hook' exists, make sure it is run.  This
  4267.     # allows users to do random weird things to the distribution
  4268.     # before it is packaged up.
  4269.     push (@dist_targets, 'dist-hook')
  4270.       if &target_defined ('dist-hook');
  4271.     $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
  4272.  
  4273.     # Defining $(DISTDIR).
  4274.     $transform{'DISTDIR'} = !variable_defined('distdir');
  4275.     $transform{'TOP_DISTDIR'} = backname ($relative_dir);
  4276.  
  4277.     $output_rules .= &file_contents ('distdir', %transform);
  4278. }
  4279.  
  4280.  
  4281. # Handle subdirectories.
  4282. sub handle_subdirs
  4283. {
  4284.     return
  4285.       unless variable_defined ('SUBDIRS');
  4286.  
  4287.     my @subdirs = &variable_value_as_list_recursive ('SUBDIRS', 'all');
  4288.     my @dsubdirs = ();
  4289.     @dsubdirs = &variable_value_as_list_recursive ('DIST_SUBDIRS', 'all')
  4290.       if variable_defined ('DIST_SUBDIRS');
  4291.  
  4292.     # If an `obj/' directory exists, BSD make will enter it before
  4293.     # reading `Makefile'.  Hence the `Makefile' in the current directory
  4294.     # will not be read.
  4295.     #
  4296.     #  % cat Makefile
  4297.     #  all:
  4298.     #          echo Hello
  4299.     #  % cat obj/Makefile
  4300.     #  all:
  4301.     #          echo World
  4302.     #  % make      # GNU make
  4303.     #  echo Hello
  4304.     #  Hello
  4305.     #  % pmake     # BSD make
  4306.     #  echo World
  4307.     #  World
  4308.     msg_var ('portability', 'SUBDIRS',
  4309.          "naming a subdirectory `obj' causes troubles with BSD make")
  4310.       if grep ($_ eq 'obj', @subdirs);
  4311.     msg_var ('portability', 'DIST_SUBDIRS',
  4312.          "naming a subdirectory `obj' causes troubles with BSD make")
  4313.       if grep ($_ eq 'obj', @dsubdirs);
  4314.  
  4315.     # Make sure each directory mentioned in SUBDIRS actually exists.
  4316.     foreach my $dir (@subdirs)
  4317.     {
  4318.     # Skip directories substituted by configure.
  4319.     next if $dir =~ /^\@.*\@$/;
  4320.  
  4321.     if (! -d $am_relative_dir . '/' . $dir)
  4322.     {
  4323.         err_var ('SUBDIRS', "required directory $am_relative_dir/$dir "
  4324.              . "does not exist");
  4325.         next;
  4326.     }
  4327.  
  4328.     err_var 'SUBDIRS', "directory should not contain `/'"
  4329.       if $dir =~ /\//;
  4330.     }
  4331.  
  4332.     $output_rules .= &file_contents ('subdirs');
  4333.     variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
  4334. }
  4335.  
  4336.  
  4337. # ($REGEN, @DEPENDENCIES)
  4338. # &scan_aclocal_m4
  4339. # ----------------
  4340. # If aclocal.m4 creation is automated, return the list of its dependencies.
  4341. sub scan_aclocal_m4
  4342. {
  4343.     my $regen_aclocal = 0;
  4344.  
  4345.     if (-f 'aclocal.m4')
  4346.     {
  4347.        # When using aclocal.m4, define this variable even in subdirectories,
  4348.        # because every Makefile.in depends on $(ACLOCAL_M4).
  4349.        &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
  4350.     }
  4351.  
  4352.     return (0, ())
  4353.       unless $relative_dir eq '.';
  4354.  
  4355.     &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
  4356.     &examine_variable ('CONFIGURE_DEPENDENCIES');
  4357.  
  4358.     if (-f 'aclocal.m4')
  4359.     {
  4360.     &push_dist_common ('aclocal.m4');
  4361.  
  4362.     my $aclocal = new Automake::XFile "< aclocal.m4";
  4363.     my $line = $aclocal->getline;
  4364.     $regen_aclocal = $line =~ 'generated automatically by aclocal';
  4365.     }
  4366.  
  4367.     my @ac_deps = ();
  4368.  
  4369.     if (-f 'acinclude.m4')
  4370.     {
  4371.     $regen_aclocal = 1;
  4372.     push @ac_deps, 'acinclude.m4';
  4373.     }
  4374.  
  4375.     if (variable_defined ('ACLOCAL_M4_SOURCES'))
  4376.     {
  4377.     push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
  4378.     }
  4379.     elsif (variable_defined ('ACLOCAL_AMFLAGS'))
  4380.     {
  4381.     # Scan all -I directories for m4 files.  These are our
  4382.     # dependencies.
  4383.     my $examine_next = 0;
  4384.     foreach my $amdir (&variable_value_as_list_recursive ('ACLOCAL_AMFLAGS', ''))
  4385.     {
  4386.         if ($examine_next)
  4387.         {
  4388.         $examine_next = 0;
  4389.         if ($amdir !~ /^\// && -d $amdir)
  4390.         {
  4391.             foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
  4392.             {
  4393.             $ac_dep =~ s/^\.\/+//;
  4394.             push (@ac_deps, $ac_dep)
  4395.               unless $ac_dep eq "aclocal.m4"
  4396.                 || $ac_dep eq "acinclude.m4";
  4397.             }
  4398.         }
  4399.         }
  4400.         elsif ($amdir eq '-I')
  4401.         {
  4402.         $examine_next = 1;
  4403.         }
  4404.     }
  4405.     }
  4406.  
  4407.     # Note that it might be possible that aclocal.m4 doesn't exist but
  4408.     # should be auto-generated.  This case probably isn't very
  4409.     # important.
  4410.  
  4411.     return ($regen_aclocal, @ac_deps);
  4412. }
  4413.  
  4414.  
  4415. # @DEPENDENCY
  4416. # &rewrite_inputs_into_dependencies ($ADD_SRCDIR, @INPUTS)
  4417. # --------------------------------------------------------
  4418. # Rewrite a list of input files into a form suitable to put on a
  4419. # dependency list.  The idea is that if an input file has a directory
  4420. # part the same as the current directory, then the directory part is
  4421. # simply removed.  But if the directory part is different, then
  4422. # $(top_srcdir) is prepended.  Among other things, this is used to
  4423. # generate the dependency list for the output files generated by
  4424. # AC_OUTPUT.  Consider what the dependencies should look like in this
  4425. # case:
  4426. #   AC_OUTPUT(src/out:src/in1:lib/in2)
  4427. # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
  4428. # If 0 then files that require this addition will simply be ignored.
  4429. sub rewrite_inputs_into_dependencies ($@)
  4430. {
  4431.     my ($add_srcdir, @inputs) = @_;
  4432.     my @newinputs;
  4433.  
  4434.     foreach my $single (@inputs)
  4435.     {
  4436.     if (dirname ($single) eq $relative_dir)
  4437.     {
  4438.         push (@newinputs, basename ($single));
  4439.     }
  4440.     elsif ($add_srcdir)
  4441.     {
  4442.         push (@newinputs, '$(top_srcdir)/' . $single);
  4443.     }
  4444.     }
  4445.  
  4446.     return @newinputs;
  4447. }
  4448.  
  4449. # Handle remaking and configure stuff.
  4450. # We need the name of the input file, to do proper remaking rules.
  4451. sub handle_configure
  4452. {
  4453.     my ($local, $input, @secondary_inputs) = @_;
  4454.  
  4455.     my $input_base = basename ($input);
  4456.     my $local_base = basename ($local);
  4457.  
  4458.     my $amfile = $input_base . '.am';
  4459.     # We know we can always add '.in' because it really should be an
  4460.     # error if the .in was missing originally.
  4461.     my $infile = '$(srcdir)/' . $input_base . '.in';
  4462.     my $colon_infile = '';
  4463.     if ($local ne $input || @secondary_inputs)
  4464.     {
  4465.     $colon_infile = ':' . $input . '.in';
  4466.     }
  4467.     $colon_infile .= ':' . join (':', @secondary_inputs)
  4468.     if @secondary_inputs;
  4469.  
  4470.     my @rewritten = rewrite_inputs_into_dependencies (1, @secondary_inputs);
  4471.  
  4472.     my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
  4473.  
  4474.     $output_rules .=
  4475.       &file_contents ('configure',
  4476.               ('MAKEFILE'
  4477.                => $local_base,
  4478.                'MAKEFILE-DEPS'
  4479.                => "@rewritten",
  4480.                'CONFIG-MAKEFILE'
  4481.                => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
  4482.                'MAKEFILE-IN'
  4483.                => $infile,
  4484.                'MAKEFILE-IN-DEPS'
  4485.                => "@include_stack",
  4486.                'MAKEFILE-AM'
  4487.                => $amfile,
  4488.                'STRICTNESS'
  4489.                => $cygnus_mode ? 'cygnus' : $strictness_name,
  4490.                'USE-DEPS'
  4491.                => $cmdline_use_dependencies ? '' : ' --ignore-deps',
  4492.                'MAKEFILE-AM-SOURCES'
  4493.                =>  "$input$colon_infile",
  4494.                'REGEN-ACLOCAL-M4'
  4495.                => $regen_aclocal_m4,
  4496.                'ACLOCAL_M4_DEPS'
  4497.                => "@aclocal_m4_deps"));
  4498.  
  4499.     if ($relative_dir eq '.')
  4500.     {
  4501.     &push_dist_common ('acconfig.h')
  4502.         if -f 'acconfig.h';
  4503.     }
  4504.  
  4505.     # If we have a configure header, require it.
  4506.     my $hdr_index = 0;
  4507.     my @distclean_config;
  4508.     foreach my $spec (@config_headers)
  4509.       {
  4510.     $hdr_index += 1;
  4511.     # $CONFIG_H_PATH: config.h from top level.
  4512.     my ($config_h_path, @ins) = split_config_file_spec ($spec);
  4513.     my $config_h_dir = dirname ($config_h_path);
  4514.  
  4515.     # If the header is in the current directory we want to build
  4516.     # the header here.  Otherwise, if we're at the topmost
  4517.     # directory and the header's directory doesn't have a
  4518.     # Makefile, then we also want to build the header.
  4519.     if ($relative_dir eq $config_h_dir
  4520.         || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
  4521.     {
  4522.         my ($cn_sans_dir, $stamp_dir);
  4523.         if ($relative_dir eq $config_h_dir)
  4524.         {
  4525.         $cn_sans_dir = basename ($config_h_path);
  4526.         $stamp_dir = '';
  4527.         }
  4528.         else
  4529.         {
  4530.         $cn_sans_dir = $config_h_path;
  4531.         if ($config_h_dir eq '.')
  4532.         {
  4533.             $stamp_dir = '';
  4534.         }
  4535.         else
  4536.         {
  4537.             $stamp_dir = $config_h_dir . '/';
  4538.         }
  4539.         }
  4540.  
  4541.         # Compute relative path from directory holding output
  4542.         # header to directory holding input header.  FIXME:
  4543.         # doesn't handle case where we have multiple inputs.
  4544.         my $in0_sans_dir;
  4545.         if (dirname ($ins[0]) eq $relative_dir)
  4546.         {
  4547.         $in0_sans_dir = basename ($ins[0]);
  4548.         }
  4549.         else
  4550.         {
  4551.             $in0_sans_dir = backname ($relative_dir) . '/' . $ins[0];
  4552.         }
  4553.  
  4554.         require_file ($config_header_location, FOREIGN, $in0_sans_dir);
  4555.  
  4556.         # Header defined and in this directory.
  4557.         my @files;
  4558.         if (-f $config_h_path . '.top')
  4559.         {
  4560.         push (@files, "$cn_sans_dir.top");
  4561.         }
  4562.         if (-f $config_h_path . '.bot')
  4563.         {
  4564.         push (@files, "$cn_sans_dir.bot");
  4565.         }
  4566.  
  4567.         push_dist_common (@files);
  4568.  
  4569.         # For now, acconfig.h can only appear in the top srcdir.
  4570.         if (-f 'acconfig.h')
  4571.         {
  4572.             push (@files, '$(top_srcdir)/acconfig.h');
  4573.         }
  4574.  
  4575.         my $stamp = "${stamp_dir}stamp-h${hdr_index}";
  4576.             $output_rules .=
  4577.           file_contents ('remake-hdr',
  4578.                  ('FILES'         => "@files",
  4579.                   'CONFIG_H'      => $cn_sans_dir,
  4580.                   'CONFIG_HIN'    => $in0_sans_dir,
  4581.                   'CONFIG_H_PATH' => $config_h_path,
  4582.                   'STAMP'         => "$stamp"));
  4583.  
  4584.         push @distclean_config, $cn_sans_dir, $stamp;
  4585.     }
  4586.     }
  4587.  
  4588.     $output_rules .= file_contents ('clean-hdr',
  4589.                     ('FILES' => "@distclean_config"))
  4590.       if @distclean_config;
  4591.  
  4592.     # Set location of mkinstalldirs.
  4593.     define_variable ('mkinstalldirs',
  4594.              ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
  4595.  
  4596.     reject_var ('CONFIG_HEADER',
  4597.         "`CONFIG_HEADER' is an anachronism; now determined "
  4598.         . "automatically\nfrom `$configure_ac'");
  4599.  
  4600.     my @config_h;
  4601.     foreach my $spec (@config_headers)
  4602.       {
  4603.     my ($out, @ins) = split_config_file_spec ($spec);
  4604.     # Generate CONFIG_HEADER define.
  4605.     if ($relative_dir eq dirname ($out))
  4606.     {
  4607.         push @config_h, basename ($out);
  4608.     }
  4609.     else
  4610.     {
  4611.         push @config_h, "\$(top_builddir)/$out";
  4612.     }
  4613.     }
  4614.     define_variable ("CONFIG_HEADER", "@config_h")
  4615.       if @config_h;
  4616.  
  4617.     # Now look for other files in this directory which must be remade
  4618.     # by config.status, and generate rules for them.
  4619.     my @actual_other_files = ();
  4620.     foreach my $lfile (@other_input_files)
  4621.     {
  4622.         my $file;
  4623.     my @inputs;
  4624.     if ($lfile =~ /^([^:]*):(.*)$/)
  4625.     {
  4626.         # This is the ":" syntax of AC_OUTPUT.
  4627.         $file = $1;
  4628.         @inputs = split (':', $2);
  4629.     }
  4630.     else
  4631.     {
  4632.         # Normal usage.
  4633.         $file = $lfile;
  4634.         @inputs = $file . '.in';
  4635.     }
  4636.  
  4637.     # Automake files should not be stored in here, but in %MAKE_LIST.
  4638.         prog_error "$lfile in \@other_input_files"
  4639.       if -f $file . '.am';
  4640.  
  4641.     my $local = basename ($file);
  4642.  
  4643.     # Make sure the dist directory for each input file is created.
  4644.     # We only have to do this at the topmost level though.  This
  4645.     # is a bit ugly but it easier than spreading out the logic,
  4646.     # especially in cases like AC_OUTPUT(foo/out:bar/in), where
  4647.     # there is no Makefile in bar/.
  4648.     if ($relative_dir eq '.')
  4649.     {
  4650.         foreach (@inputs)
  4651.         {
  4652.         $dist_dirs{dirname ($_)} = 1;
  4653.         }
  4654.     }
  4655.  
  4656.     # We skip files that aren't in this directory.  However, if
  4657.     # the file's directory does not have a Makefile, and we are
  4658.     # currently doing `.', then we create a rule to rebuild the
  4659.     # file in the subdir.
  4660.     my $fd = dirname ($file);
  4661.     if ($fd ne $relative_dir)
  4662.     {
  4663.         if ($relative_dir eq '.' && ! &is_make_dir ($fd))
  4664.         {
  4665.         $local = $file;
  4666.         }
  4667.         else
  4668.         {
  4669.         next;
  4670.         }
  4671.     }
  4672.  
  4673.     my @rewritten_inputs = rewrite_inputs_into_dependencies (1, @inputs);
  4674.     $output_rules .= ($local . ': '
  4675.               . '$(top_builddir)/config.status '
  4676.               . "@rewritten_inputs\n"
  4677.               . "\t"
  4678.               . 'cd $(top_builddir) && '
  4679.               . '$(SHELL) ./config.status '
  4680.               . ($relative_dir eq '.' ? '' : '$(subdir)/')
  4681.                  . '$@'
  4682.               . "\n");
  4683.     push (@actual_other_files, $local);
  4684.  
  4685.     # Require all input files.
  4686.     require_file ($ac_config_files_location, FOREIGN,
  4687.               rewrite_inputs_into_dependencies (0, @inputs));
  4688.     }
  4689.  
  4690.     # These files get removed by "make clean".
  4691.     define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
  4692. }
  4693.  
  4694. # Handle C headers.
  4695. sub handle_headers
  4696. {
  4697.     my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
  4698.                  'oldinclude', 'pkginclude',
  4699.                  'noinst', 'check');
  4700.     foreach (@r)
  4701.     {
  4702.     next unless /\..*$/;
  4703.     &saw_extension ($&);
  4704.     }
  4705. }
  4706.  
  4707. sub handle_gettext
  4708. {
  4709.   return if ! $seen_gettext || $relative_dir ne '.';
  4710.  
  4711.   if (! variable_defined ('SUBDIRS'))
  4712.     {
  4713.       err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
  4714.       return;
  4715.     }
  4716.  
  4717.   # Perform some sanity checks to help users get the right setup.
  4718.   # We disable these tests when po/ doesn't exist in order not to disallow
  4719.   # unusual gettext setups.
  4720.   #
  4721.   # Bruno Haible:
  4722.   # | The idea is:
  4723.   # |
  4724.   # |  1) If a package doesn't have a directory po/ at top level, it
  4725.   # |     will likely have multiple po/ directories in subpackages.
  4726.   # |
  4727.   # |  2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
  4728.   # |     is used without 'external'. It is also useful to warn for the
  4729.   # |     presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
  4730.   # |     warnings apply only to the usual layout of packages, therefore
  4731.   # |     they should both be disabled if no po/ directory is found at
  4732.   # |     top level.
  4733.  
  4734.   if (-d 'po')
  4735.     {
  4736.       my @subdirs = &variable_value_as_list_recursive ('SUBDIRS', 'all');
  4737.  
  4738.       msg_var ('syntax', 'SUBDIRS',
  4739.            "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
  4740.     if ! grep ($_ eq 'po', @subdirs);
  4741.  
  4742.       # intl/ is not required when AM_GNU_GETTEXT is called with
  4743.       # the `external' option.
  4744.       msg_var ('syntax', 'SUBDIRS',
  4745.            "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
  4746.     if (! $seen_gettext_external
  4747.         && ! grep ($_ eq 'intl', @subdirs));
  4748.  
  4749.       # intl/ should not be used with AM_GNU_GETTEXT([external])
  4750.       msg_var ('syntax', 'SUBDIRS',
  4751.            "`intl' should not be in SUBDIRS when "
  4752.            . "AM_GNU_GETTEXT([external]) is used")
  4753.     if ($seen_gettext_external && grep ($_ eq 'intl', @subdirs));
  4754.     }
  4755.  
  4756.   require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
  4757. }
  4758.  
  4759. # Handle footer elements.
  4760. sub handle_footer
  4761. {
  4762.     # NOTE don't use define_pretty_variable here, because
  4763.     # $contents{...} is already defined.
  4764.     $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
  4765.       if variable_value ('SOURCES');
  4766.  
  4767.     reject_target ('.SUFFIXES',
  4768.            "use variable `SUFFIXES', not target `.SUFFIXES'");
  4769.  
  4770.     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
  4771.     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
  4772.     # anything else, by sticking it right after the default: target.
  4773.     $output_header .= ".SUFFIXES:\n";
  4774.     if (@suffixes || variable_defined ('SUFFIXES'))
  4775.     {
  4776.     # Make sure suffixes has unique elements.  Sort them to ensure
  4777.     # the output remains consistent.  However, $(SUFFIXES) is
  4778.     # always at the start of the list, unsorted.  This is done
  4779.     # because make will choose rules depending on the ordering of
  4780.     # suffixes, and this lets the user have some control.  Push
  4781.     # actual suffixes, and not $(SUFFIXES).  Some versions of make
  4782.     # do not like variable substitutions on the .SUFFIXES line.
  4783.     my @user_suffixes = (variable_defined ('SUFFIXES')
  4784.                  ? &variable_value_as_list_recursive ('SUFFIXES', '')
  4785.                  : ());
  4786.  
  4787.     my %suffixes = map { $_ => 1 } @suffixes;
  4788.     delete @suffixes{@user_suffixes};
  4789.  
  4790.     $output_header .= (".SUFFIXES: "
  4791.                . join (' ', @user_suffixes, sort keys %suffixes)
  4792.                . "\n");
  4793.     }
  4794.  
  4795.     $output_trailer .= file_contents ('footer');
  4796. }
  4797.  
  4798.  
  4799. # Generate `make install' rules.
  4800. sub handle_install ()
  4801. {
  4802.   $output_rules .= &file_contents
  4803.     ('install',
  4804.      maybe_BUILT_SOURCES => (variable_defined ('BUILT_SOURCES')
  4805.                  ? (" \$(BUILT_SOURCES)\n"
  4806.                 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
  4807.                  : ''),
  4808.      'installdirs-local' => (target_defined ('installdirs-local')
  4809.                  ? ' installdirs-local' : ''),
  4810.      am__installdirs => variable_value ('am__installdirs') || '');
  4811. }
  4812.  
  4813.  
  4814. # Deal with all and all-am.
  4815. sub handle_all ($)
  4816. {
  4817.     my ($makefile) = @_;
  4818.  
  4819.     # Output `all-am'.
  4820.  
  4821.     # Put this at the beginning for the sake of non-GNU makes.  This
  4822.     # is still wrong if these makes can run parallel jobs.  But it is
  4823.     # right enough.
  4824.     unshift (@all, basename ($makefile));
  4825.  
  4826.     foreach my $spec (@config_headers)
  4827.       {
  4828.         my ($out, @ins) = split_config_file_spec ($spec);
  4829.     push (@all, basename ($out))
  4830.       if dirname ($out) eq $relative_dir;
  4831.       }
  4832.  
  4833.     # Install `all' hooks.
  4834.     if (&target_defined ("all-local"))
  4835.     {
  4836.       push (@all, "all-local");
  4837.       &depend ('.PHONY', "all-local");
  4838.     }
  4839.  
  4840.     &pretty_print_rule ("all-am:", "\t\t", @all);
  4841.     &depend ('.PHONY', 'all-am', 'all');
  4842.  
  4843.  
  4844.     # Output `all'.
  4845.  
  4846.     my @local_headers = ();
  4847.     push @local_headers, '$(BUILT_SOURCES)'
  4848.       if variable_defined ('BUILT_SOURCES');
  4849.     foreach my $spec (@config_headers)
  4850.       {
  4851.         my ($out, @ins) = split_config_file_spec ($spec);
  4852.     push @local_headers, basename ($out)
  4853.       if dirname ($out) eq $relative_dir;
  4854.       }
  4855.  
  4856.     if (@local_headers)
  4857.       {
  4858.     # We need to make sure config.h is built before we recurse.
  4859.     # We also want to make sure that built sources are built
  4860.     # before any ordinary `all' targets are run.  We can't do this
  4861.     # by changing the order of dependencies to the "all" because
  4862.     # that breaks when using parallel makes.  Instead we handle
  4863.     # things explicitly.
  4864.     $output_all .= ("all: @local_headers"
  4865.             . "\n\t"
  4866.             . '$(MAKE) $(AM_MAKEFLAGS) '
  4867.             . (variable_defined ('SUBDIRS')
  4868.                ? 'all-recursive' : 'all-am')
  4869.             . "\n\n");
  4870.       }
  4871.     else
  4872.       {
  4873.     $output_all .= "all: " . (variable_defined ('SUBDIRS')
  4874.                   ? 'all-recursive' : 'all-am') . "\n\n";
  4875.       }
  4876. }
  4877.  
  4878.  
  4879. # Handle check merge target specially.
  4880. sub do_check_merge_target
  4881. {
  4882.     if (&target_defined ('check-local'))
  4883.     {
  4884.     # User defined local form of target.  So include it.
  4885.     push (@check_tests, 'check-local');
  4886.     &depend ('.PHONY', 'check-local');
  4887.     }
  4888.  
  4889.     # In --cygnus mode, check doesn't depend on all.
  4890.     if ($cygnus_mode)
  4891.     {
  4892.     # Just run the local check rules.
  4893.     &pretty_print_rule ('check-am:', "\t\t", @check);
  4894.     }
  4895.     else
  4896.     {
  4897.     # The check target must depend on the local equivalent of
  4898.     # `all', to ensure all the primary targets are built.  Then it
  4899.     # must build the local check rules.
  4900.     $output_rules .= "check-am: all-am\n";
  4901.     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
  4902.                 @check)
  4903.         if @check;
  4904.     }
  4905.     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
  4906.             @check_tests)
  4907.     if @check_tests;
  4908.  
  4909.     &depend ('.PHONY', 'check', 'check-am');
  4910.     # Handle recursion.  We have to honor BUILT_SOURCES like for `all:'.
  4911.     $output_rules .= ("check: "
  4912.               . (variable_defined ('BUILT_SOURCES')
  4913.              ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
  4914.              : '')
  4915.               . (variable_defined ('SUBDIRS')
  4916.              ? 'check-recursive' : 'check-am')
  4917.               . "\n");
  4918. }
  4919.  
  4920. # Handle all 'clean' targets.
  4921. sub handle_clean
  4922. {
  4923.   # Clean the files listed in user variables if they exist.
  4924.   $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
  4925.     if variable_defined ('MOSTLYCLEANFILES');
  4926.   $clean_files{'$(CLEANFILES)'} = CLEAN
  4927.     if variable_defined ('CLEANFILES');
  4928.   $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
  4929.     if variable_defined ('DISTCLEANFILES');
  4930.   $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
  4931.     if variable_defined ('MAINTAINERCLEANFILES');
  4932.  
  4933.   # Built sources are automatically removed by maintainer-clean.
  4934.   $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
  4935.     if variable_defined ('BUILT_SOURCES');
  4936.  
  4937.   # Compute a list of "rm"s to run for each target.
  4938.   my %rms = (MOSTLY_CLEAN, [],
  4939.          CLEAN, [],
  4940.          DIST_CLEAN, [],
  4941.          MAINTAINER_CLEAN, []);
  4942.  
  4943.   foreach my $file (keys %clean_files)
  4944.     {
  4945.       my $when = $clean_files{$file};
  4946.       prog_error 'invalid entry in %clean_files'
  4947.     unless exists $rms{$when};
  4948.  
  4949.       my $rm = "rm -f $file";
  4950.       # If file is a variable, make sure when don't call `rm -f' without args.
  4951.       $rm ="test -z \"$file\" || $rm"
  4952.     if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
  4953.  
  4954.       push @{$rms{$when}}, "\t-$rm\n";
  4955.     }
  4956.  
  4957.   $output_rules .= &file_contents
  4958.     ('clean',
  4959.      MOSTLYCLEAN_RMS      => join ('', @{$rms{&MOSTLY_CLEAN}}),
  4960.      CLEAN_RMS            => join ('', @{$rms{&CLEAN}}),
  4961.      DISTCLEAN_RMS        => join ('', @{$rms{&DIST_CLEAN}}),
  4962.      MAINTAINER_CLEAN_RMS => join ('', @{$rms{&MAINTAINER_CLEAN}}));
  4963. }
  4964.  
  4965.  
  4966. # &depend ($CATEGORY, @DEPENDEES)
  4967. # -------------------------------
  4968. # The target $CATEGORY depends on @DEPENDEES.
  4969. sub depend
  4970. {
  4971.     my ($category, @dependees) = @_;
  4972.     {
  4973.       push (@{$dependencies{$category}}, @dependees);
  4974.     }
  4975. }
  4976.  
  4977.  
  4978. # &target_cmp ($A, $B)
  4979. # --------------------
  4980. # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
  4981. sub target_cmp
  4982. {
  4983.     return 0
  4984.         if $a eq $b;
  4985.     return -1
  4986.         if $b eq '.PHONY';
  4987.     return 1
  4988.         if $a eq '.PHONY';
  4989.     return $a cmp $b;
  4990. }
  4991.  
  4992.  
  4993. # &handle_factored_dependencies ()
  4994. # --------------------------------
  4995. # Handle everything related to gathered targets.
  4996. sub handle_factored_dependencies
  4997. {
  4998.   # Reject bad hooks.
  4999.   foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
  5000.              'uninstall-exec-local', 'uninstall-exec-hook')
  5001.     {
  5002.       my $x = $utarg;
  5003.       $x =~ s/(data|exec)-//;
  5004.       reject_target ($utarg, "use `$x', not `$utarg'");
  5005.     }
  5006.  
  5007.   reject_target ('install-local',
  5008.          "use `install-data-local' or `install-exec-local', "
  5009.          . "not `install-local'");
  5010.  
  5011.   reject_target ('install-info-local',
  5012.          "`install-info-local' target defined but "
  5013.          . "`no-installinfo' option not in use")
  5014.     unless defined $options{'no-installinfo'};
  5015.  
  5016.   # Install the -local hooks.
  5017.   foreach (keys %dependencies)
  5018.     {
  5019.       # Hooks are installed on the -am targets.
  5020.       s/-am$// or next;
  5021.       if (&target_defined ("$_-local"))
  5022.     {
  5023.       depend ("$_-am", "$_-local");
  5024.       &depend ('.PHONY', "$_-local");
  5025.     }
  5026.     }
  5027.  
  5028.   # Install the -hook hooks.
  5029.   # FIXME: Why not be as liberal as we are with -local hooks?
  5030.   foreach ('install-exec', 'install-data', 'uninstall')
  5031.     {
  5032.       if (&target_defined ("$_-hook"))
  5033.     {
  5034.       $actions{"$_-am"} .=
  5035.         ("\t\@\$(NORMAL_INSTALL)\n"
  5036.          . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
  5037.     }
  5038.     }
  5039.  
  5040.   # All the required targets are phony.
  5041.   depend ('.PHONY', keys %required_targets);
  5042.  
  5043.   # Actually output gathered targets.
  5044.   foreach (sort target_cmp keys %dependencies)
  5045.     {
  5046.       # If there is nothing about this guy, skip it.
  5047.       next
  5048.     unless (@{$dependencies{$_}}
  5049.         || $actions{$_}
  5050.         || $required_targets{$_});
  5051.       &pretty_print_rule ("$_:", "\t",
  5052.               uniq (sort @{$dependencies{$_}}));
  5053.       $output_rules .= $actions{$_}
  5054.       if defined $actions{$_};
  5055.       $output_rules .= "\n";
  5056.     }
  5057. }
  5058.  
  5059.  
  5060. # &handle_tests_dejagnu ()
  5061. # ------------------------
  5062. sub handle_tests_dejagnu
  5063. {
  5064.     push (@check_tests, 'check-DEJAGNU');
  5065.     $output_rules .= file_contents ('dejagnu');
  5066. }
  5067.  
  5068.  
  5069. # Handle TESTS variable and other checks.
  5070. sub handle_tests
  5071. {
  5072.   if (defined $options{'dejagnu'})
  5073.     {
  5074.       &handle_tests_dejagnu;
  5075.     }
  5076.   else
  5077.     {
  5078.       foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
  5079.     {
  5080.       reject_var ($c, "`$c' defined but `dejagnu' not in "
  5081.               . "`AUTOMAKE_OPTIONS'");
  5082.     }
  5083.     }
  5084.  
  5085.   if (variable_defined ('TESTS'))
  5086.     {
  5087.       push (@check_tests, 'check-TESTS');
  5088.       $output_rules .= &file_contents ('check');
  5089.     }
  5090. }
  5091.  
  5092. # Handle Emacs Lisp.
  5093. sub handle_emacs_lisp
  5094. {
  5095.   my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
  5096.                  'lisp', 'noinst');
  5097.  
  5098.   return if ! @elfiles;
  5099.  
  5100.   # Generate .elc files.
  5101.   my @elcfiles = map { $_ . 'c' } @elfiles;
  5102.   define_pretty_variable ('ELCFILES', '', @elcfiles);
  5103.  
  5104.   define_pretty_variable ('am__ELFILES', '', @elfiles);
  5105.  
  5106.   # Do not depend on the build rules if ELCFILES is empty.
  5107.   # This is necessary because overriding ELCFILES= is a documented
  5108.   # idiom to disable byte-compilation.
  5109.   if (variable_value ('ELCFILES'))
  5110.     {
  5111.       # It's important that all depends on elc-stamp so that
  5112.       # all .elc files get recompiled whenever a .el changes.
  5113.       # It's important that all depends on $(ELCFILES) so that
  5114.       # we can recover if any of them is deleted.
  5115.       push (@all, 'elc-stamp', '$(ELCFILES)');
  5116.     }
  5117.  
  5118.   require_variables ("$am_file.am", "Emacs Lisp sources seen", 'TRUE',
  5119.              'EMACS', 'lispdir');
  5120.   require_conf_file ("$am_file.am", FOREIGN, 'elisp-comp');
  5121.   &define_variable ('elisp_comp', $config_aux_dir . '/elisp-comp');
  5122. }
  5123.  
  5124. # Handle Python
  5125. sub handle_python
  5126. {
  5127.   my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
  5128.                  'noinst');
  5129.   return if ! @pyfiles;
  5130.  
  5131.   require_variables ("$am_file.am", "Python sources seen", 'TRUE',
  5132.              'PYTHON');
  5133.   require_conf_file ("$am_file.am", FOREIGN, 'py-compile');
  5134.   &define_variable ('py_compile', $config_aux_dir . '/py-compile');
  5135. }
  5136.  
  5137. # Handle Java.
  5138. sub handle_java
  5139. {
  5140.     my @sourcelist = &am_install_var ('-candist',
  5141.                       'java', 'JAVA',
  5142.                       'java', 'noinst', 'check');
  5143.     return if ! @sourcelist;
  5144.  
  5145.     my @prefix = am_primary_prefixes ('JAVA', 1,
  5146.                       'java', 'noinst', 'check');
  5147.  
  5148.     my $dir;
  5149.     foreach my $curs (@prefix)
  5150.       {
  5151.     next
  5152.       if $curs eq 'EXTRA';
  5153.  
  5154.     err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
  5155.       if defined $dir;
  5156.     $dir = $curs;
  5157.       }
  5158.  
  5159.  
  5160.     push (@all, 'class' . $dir . '.stamp');
  5161. }
  5162.  
  5163.  
  5164. # Handle some of the minor options.
  5165. sub handle_minor_options
  5166. {
  5167.   if (defined $options{'readme-alpha'})
  5168.     {
  5169.       if ($relative_dir eq '.')
  5170.     {
  5171.       if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
  5172.         {
  5173.           msg ('error-gnits', $package_version_location,
  5174.            "version `$package_version' doesn't follow " .
  5175.            "Gnits standards");
  5176.         }
  5177.       if (defined $1 && -f 'README-alpha')
  5178.         {
  5179.           # This means we have an alpha release.  See
  5180.           # GNITS_VERSION_PATTERN for details.
  5181.           push_dist_common ('README-alpha');
  5182.         }
  5183.     }
  5184.     }
  5185. }
  5186.  
  5187. ################################################################
  5188.  
  5189. # ($OUTPUT, @INPUTS)
  5190. # &split_config_file_spec ($SPEC)
  5191. # -------------------------------
  5192. # Decode the Autoconf syntax for config files (files, headers, links
  5193. # etc.).
  5194. sub split_config_file_spec ($)
  5195. {
  5196.   my ($spec) = @_;
  5197.   my ($output, @inputs) = split (/:/, $spec);
  5198.  
  5199.   push @inputs, "$output.in"
  5200.     unless @inputs;
  5201.  
  5202.   return ($output, @inputs);
  5203. }
  5204.  
  5205.  
  5206. my %make_list;
  5207.  
  5208. # &scan_autoconf_config_files ($CONFIG-FILES)
  5209. # -------------------------------------------
  5210. # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
  5211. # (or AC_OUTPUT).
  5212. sub scan_autoconf_config_files
  5213. {
  5214.     my ($config_files) = @_;
  5215.     # Look at potential Makefile.am's.
  5216.     foreach (split ' ', $config_files)
  5217.     {
  5218.         # Must skip empty string for Perl 4.
  5219.         next if $_ eq "\\" || $_ eq '';
  5220.  
  5221.         # Handle $local:$input syntax.  Note that we ignore
  5222.         # every input file past the first, though we keep
  5223.         # those around for later.
  5224.         my ($local, $input, @rest) = split (/:/);
  5225.         if (! $input)
  5226.         {
  5227.             $input = $local;
  5228.         }
  5229.         else
  5230.         {
  5231.             # FIXME: should be error if .in is missing.
  5232.             $input =~ s/\.in$//;
  5233.         }
  5234.  
  5235.         if (-f $input . '.am')
  5236.         {
  5237.             # We have a file that automake should generate.
  5238.             $make_list{$input} = join (':', ($local, @rest));
  5239.         }
  5240.         else
  5241.         {
  5242.             # We have a file that automake should cause to be
  5243.             # rebuilt, but shouldn't generate itself.
  5244.             push (@other_input_files, $_);
  5245.         }
  5246.     }
  5247. }
  5248.  
  5249.  
  5250. # &scan_autoconf_traces ($FILENAME)
  5251. # ---------------------------------
  5252. sub scan_autoconf_traces ($)
  5253. {
  5254.   my ($filename) = @_;
  5255.  
  5256.   my %traced = (
  5257.         AC_CANONICAL_HOST => 0,
  5258.         AC_CANONICAL_SYSTEM => 0,
  5259.         AC_CONFIG_AUX_DIR => 1,
  5260.         AC_CONFIG_FILES => 1,
  5261.         AC_CONFIG_HEADERS => 1,
  5262.         AC_INIT => 0,
  5263.         AC_LIBSOURCE => 1,
  5264.         AC_SUBST => 1,
  5265.         AM_AUTOMAKE_VERSION => 1,
  5266.         AM_CONDITIONAL => 2,
  5267.         AM_ENABLE_MULTILIB => 0,
  5268.         AM_GNU_GETTEXT => 0,
  5269.         AM_INIT_AUTOMAKE => 0,
  5270.         AM_MAINTAINER_MODE => 0,
  5271.         AM_PROG_CC_C_O => 0,
  5272.         );
  5273.  
  5274.   my $traces = ($ENV{AUTOCONF} || 'autoconf') . " ";
  5275.  
  5276.   # Use a separator unlikely to be used, not `:', the default, which
  5277.   # has a precise meaning for AC_CONFIG_FILES and so on.
  5278.   $traces .= join (' ',
  5279.            map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' }
  5280.            (keys %traced));
  5281.  
  5282.   my $tracefh = new Automake::XFile ("$traces $filename |");
  5283.   verb "reading $traces";
  5284.  
  5285.   while ($_ = $tracefh->getline)
  5286.     {
  5287.       chomp;
  5288.       my ($here, @args) = split /::/;
  5289.       my $macro = $args[0];
  5290.  
  5291.       prog_error ("unrequested trace `$macro'")
  5292.     unless exists $traced{$macro};
  5293.  
  5294.       # Skip and diagnose malformed calls.
  5295.       if ($#args < $traced{$macro})
  5296.     {
  5297.       msg ('syntax', $here, "not enough arguments for $macro");
  5298.       next;
  5299.     }
  5300.  
  5301.       # Alphabetical ordering please.
  5302.       if ($macro eq 'AC_CANONICAL_HOST')
  5303.     {
  5304.       if (! $seen_canonical)
  5305.         {
  5306.           $seen_canonical = AC_CANONICAL_HOST;
  5307.           $canonical_location = $here;
  5308.         };
  5309.     }
  5310.       elsif ($macro eq 'AC_CANONICAL_SYSTEM')
  5311.     {
  5312.       $seen_canonical = AC_CANONICAL_SYSTEM;
  5313.       $canonical_location = $here;
  5314.     }
  5315.       elsif ($macro eq 'AC_CONFIG_AUX_DIR')
  5316.     {
  5317.       @config_aux_path = $args[1];
  5318.       $config_aux_dir_set_in_configure_in = 1;
  5319.     }
  5320.       elsif ($macro eq 'AC_CONFIG_FILES')
  5321.     {
  5322.       # Look at potential Makefile.am's.
  5323.       $ac_config_files_location = $here;
  5324.       &scan_autoconf_config_files ($args[1]);
  5325.     }
  5326.       elsif ($macro eq 'AC_CONFIG_HEADERS')
  5327.     {
  5328.       $config_header_location = $here;
  5329.       push @config_headers, split (' ', $args[1]);
  5330.     }
  5331.       elsif ($macro eq 'AC_INIT')
  5332.         {
  5333.       if (defined $args[2])
  5334.         {
  5335.           $package_version = $args[2];
  5336.           $package_version_location = $here;
  5337.         }
  5338.     }
  5339.       elsif ($macro eq 'AC_LIBSOURCE')
  5340.     {
  5341.       $libsources{$args[1]} = $here;
  5342.     }
  5343.       elsif ($macro eq 'AC_SUBST')
  5344.     {
  5345.       # Just check for alphanumeric in AC_SUBST.  If you do
  5346.       # AC_SUBST(5), then too bad.
  5347.       $configure_vars{$args[1]} = $here
  5348.         if $args[1] =~ /^\w+$/;
  5349.     }
  5350.       elsif ($macro eq 'AM_AUTOMAKE_VERSION')
  5351.         {
  5352.       error ($here,
  5353.          "version mismatch.  This is Automake $VERSION,\n" .
  5354.          "but the definition used by this AM_INIT_AUTOMAKE\n" .
  5355.          "comes from Automake $args[1].  You should recreate\n" .
  5356.          "aclocal.m4 with aclocal and run automake again.\n")
  5357.         if $VERSION ne $args[1];
  5358.  
  5359.       $seen_automake_version = 1;
  5360.         }
  5361.       elsif ($macro eq 'AM_CONDITIONAL')
  5362.     {
  5363.       $configure_cond{$args[1]} = $here;
  5364.     }
  5365.       elsif ($macro eq 'AM_ENABLE_MULTILIB')
  5366.     {
  5367.       $seen_multilib = $here;
  5368.     }
  5369.       elsif ($macro eq 'AM_GNU_GETTEXT')
  5370.     {
  5371.       $seen_gettext = $here;
  5372.       $ac_gettext_location = $here;
  5373.       $seen_gettext_external = grep ($_ eq 'external', @args);
  5374.     }
  5375.       elsif ($macro eq 'AM_INIT_AUTOMAKE')
  5376.     {
  5377.       $seen_init_automake = $here;
  5378.       if (defined $args[2])
  5379.         {
  5380.           $package_version = $args[2];
  5381.           $package_version_location = $here;
  5382.         }
  5383.       elsif (defined $args[1])
  5384.         {
  5385.           $global_options = $args[1];
  5386.         }
  5387.     }
  5388.       elsif ($macro eq 'AM_MAINTAINER_MODE')
  5389.     {
  5390.       $seen_maint_mode = $here;
  5391.     }
  5392.       elsif ($macro eq 'AM_PROG_CC_C_O')
  5393.     {
  5394.       $seen_cc_c_o = $here;
  5395.     }
  5396.    }
  5397. }
  5398.  
  5399.  
  5400. # &scan_autoconf_files ()
  5401. # -----------------------
  5402. # Check whether we use `configure.ac' or `configure.in'.
  5403. # Scan it (and possibly `aclocal.m4') for interesting things.
  5404. # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
  5405. sub scan_autoconf_files
  5406. {
  5407.     # Reinitialize libsources here.  This isn't really necessary,
  5408.     # since we currently assume there is only one configure.ac.  But
  5409.     # that won't always be the case.
  5410.     %libsources = ();
  5411.  
  5412.     $configure_ac = find_configure_ac;
  5413.     fatal "`configure.ac' or `configure.in' is required\n"
  5414.         if !$configure_ac;
  5415.  
  5416.     scan_autoconf_traces ($configure_ac);
  5417.  
  5418.     # Set input and output files if not specified by user.
  5419.     if (! @input_files)
  5420.     {
  5421.     @input_files = sort keys %make_list;
  5422.     %output_files = %make_list;
  5423.     }
  5424.  
  5425.     @configure_input_files = sort keys %make_list;
  5426.  
  5427.     if (! $seen_init_automake)
  5428.       {
  5429.     err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
  5430.         . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
  5431.         . "\nthat aclocal.m4 is present in the top-level directory,\n"
  5432.         . "and that aclocal.m4 was recently regenerated "
  5433.         . "(using aclocal).");
  5434.       }
  5435.     else
  5436.       {
  5437.     if (! $seen_automake_version)
  5438.       {
  5439.         if (-f 'aclocal.m4')
  5440.           {
  5441.         error ($seen_init_automake,
  5442.                "your implementation of AM_INIT_AUTOMAKE comes from " .
  5443.                "an\nold Automake version.  You should recreate " .
  5444.                "aclocal.m4\nwith aclocal and run automake again.\n");
  5445.           }
  5446.         else
  5447.           {
  5448.         error ($seen_init_automake,
  5449.                "no proper implementation of AM_INIT_AUTOMAKE was " .
  5450.                "found,\nprobably because aclocal.m4 is missing...\n" .
  5451.                "You should run aclocal to create this file, then\n" .
  5452.                "run automake again.\n");
  5453.           }
  5454.       }
  5455.       }
  5456.  
  5457.     # Look for some files we need.  Always check for these.  This
  5458.     # check must be done for every run, even those where we are only
  5459.     # looking at a subdir Makefile.  We must set relative_dir so that
  5460.     # the file-finding machinery works.
  5461.     # FIXME: Is this broken because it needs dynamic scopes.
  5462.     # My tests seems to show it's not the case.
  5463.     $relative_dir = '.';
  5464.     require_conf_file ($configure_ac, FOREIGN,
  5465.                'install-sh', 'mkinstalldirs', 'missing');
  5466.     err_am "`install.sh' is an anachronism; use `install-sh' instead"
  5467.       if -f $config_aux_path[0] . '/install.sh';
  5468.  
  5469.     # Preserve dist_common for later.
  5470.     $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
  5471. }
  5472.  
  5473. ################################################################
  5474.  
  5475. # Set up for Cygnus mode.
  5476. sub check_cygnus
  5477. {
  5478.   return unless $cygnus_mode;
  5479.  
  5480.   &set_strictness ('foreign');
  5481.   $options{'no-installinfo'} = $cygnus_mode;
  5482.   $options{'no-dependencies'} = $cygnus_mode;
  5483.   $use_dependencies = 0;
  5484.  
  5485.   err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
  5486.     if !$seen_maint_mode;
  5487. }
  5488.  
  5489. # Do any extra checking for GNU standards.
  5490. sub check_gnu_standards
  5491. {
  5492.   if ($relative_dir eq '.')
  5493.     {
  5494.       # In top level (or only) directory.
  5495.  
  5496.       # Accept one of these three licenses; default to COPYING.
  5497.       my $license = 'COPYING';
  5498.       foreach (qw /COPYING.LIB COPYING.LESSER/)
  5499.     {
  5500.       $license = $_ if -f $_;
  5501.     }
  5502.       require_file ("$am_file.am", GNU, $license,
  5503.             qw/INSTALL NEWS README AUTHORS ChangeLog/);
  5504.     }
  5505.  
  5506.   for my $opt ('no-installman', 'no-installinfo')
  5507.     {
  5508.       msg ('error-gnu', $options{$opt},
  5509.        "option `$opt' disallowed by GNU standards")
  5510.     if (defined $options{$opt});
  5511.     }
  5512. }
  5513.  
  5514. # Do any extra checking for GNITS standards.
  5515. sub check_gnits_standards
  5516. {
  5517.   if ($relative_dir eq '.')
  5518.     {
  5519.       # In top level (or only) directory.
  5520.       require_file ("$am_file.am", GNITS, 'THANKS');
  5521.     }
  5522. }
  5523.  
  5524. ################################################################
  5525. #
  5526. # Functions to handle files of each language.
  5527.  
  5528. # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
  5529. # simple formula: Return value is LANG_SUBDIR if the resulting object
  5530. # file should be in a subdir if the source file is, LANG_PROCESS if
  5531. # file is to be dealt with, LANG_IGNORE otherwise.
  5532.  
  5533. # Much of the actual processing is handled in
  5534. # handle_single_transform_list.  These functions exist so that
  5535. # auxiliary information can be recorded for a later cleanup pass.
  5536. # Note that the calls to these functions are computed, so don't bother
  5537. # searching for their precise names in the source.
  5538.  
  5539. # This is just a convenience function that can be used to determine
  5540. # when a subdir object should be used.
  5541. sub lang_sub_obj
  5542. {
  5543.     return defined $options{'subdir-objects'} ? LANG_SUBDIR : LANG_PROCESS;
  5544. }
  5545.  
  5546. # Rewrite a single C source file.
  5547. sub lang_c_rewrite
  5548. {
  5549.   my ($directory, $base, $ext) = @_;
  5550.  
  5551.   if (defined $options{'ansi2knr'} && $base =~ /_$/)
  5552.     {
  5553.       # FIXME: include line number in error.
  5554.       err_am "C source file `$base.c' would be deleted by ansi2knr rules";
  5555.     }
  5556.  
  5557.   my $r = LANG_PROCESS;
  5558.   if (defined $options{'subdir-objects'})
  5559.     {
  5560.       $r = LANG_SUBDIR;
  5561.       $base = $directory . '/' . $base
  5562.     unless $directory eq '.' || $directory eq '';
  5563.  
  5564.       err_am ("C objects in subdir but `AM_PROG_CC_C_O' "
  5565.           . "not in `$configure_ac'",
  5566.           uniq_scope => US_GLOBAL)
  5567.     unless $seen_cc_c_o;
  5568.  
  5569.       require_conf_file ("$am_file.am", FOREIGN, 'compile');
  5570.  
  5571.       # In this case we already have the directory information, so
  5572.       # don't add it again.
  5573.       $de_ansi_files{$base} = '';
  5574.     }
  5575.   else
  5576.     {
  5577.       $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
  5578.                    ? ''
  5579.                    : "$directory/");
  5580.     }
  5581.  
  5582.     return $r;
  5583. }
  5584.  
  5585. # Rewrite a single C++ source file.
  5586. sub lang_cxx_rewrite
  5587. {
  5588.     return &lang_sub_obj;
  5589. }
  5590.  
  5591. # Rewrite a single header file.
  5592. sub lang_header_rewrite
  5593. {
  5594.     # Header files are simply ignored.
  5595.     return LANG_IGNORE;
  5596. }
  5597.  
  5598. # Rewrite a single yacc file.
  5599. sub lang_yacc_rewrite
  5600. {
  5601.     my ($directory, $base, $ext) = @_;
  5602.  
  5603.     my $r = &lang_sub_obj;
  5604.     (my $newext = $ext) =~ tr/y/c/;
  5605.     return ($r, $newext);
  5606. }
  5607.  
  5608. # Rewrite a single yacc++ file.
  5609. sub lang_yaccxx_rewrite
  5610. {
  5611.     my ($directory, $base, $ext) = @_;
  5612.  
  5613.     my $r = &lang_sub_obj;
  5614.     (my $newext = $ext) =~ tr/y/c/;
  5615.     return ($r, $newext);
  5616. }
  5617.  
  5618. # Rewrite a single lex file.
  5619. sub lang_lex_rewrite
  5620. {
  5621.     my ($directory, $base, $ext) = @_;
  5622.  
  5623.     my $r = &lang_sub_obj;
  5624.     (my $newext = $ext) =~ tr/l/c/;
  5625.     return ($r, $newext);
  5626. }
  5627.  
  5628. # Rewrite a single lex++ file.
  5629. sub lang_lexxx_rewrite
  5630. {
  5631.     my ($directory, $base, $ext) = @_;
  5632.  
  5633.     my $r = &lang_sub_obj;
  5634.     (my $newext = $ext) =~ tr/l/c/;
  5635.     return ($r, $newext);
  5636. }
  5637.  
  5638. # Rewrite a single assembly file.
  5639. sub lang_asm_rewrite
  5640. {
  5641.     return &lang_sub_obj;
  5642. }
  5643.  
  5644. # Rewrite a single Fortran 77 file.
  5645. sub lang_f77_rewrite
  5646. {
  5647.     return LANG_PROCESS;
  5648. }
  5649.  
  5650. # Rewrite a single preprocessed Fortran 77 file.
  5651. sub lang_ppf77_rewrite
  5652. {
  5653.     return LANG_PROCESS;
  5654. }
  5655.  
  5656. # Rewrite a single ratfor file.
  5657. sub lang_ratfor_rewrite
  5658. {
  5659.     return LANG_PROCESS;
  5660. }
  5661.  
  5662. # Rewrite a single Objective C file.
  5663. sub lang_objc_rewrite
  5664. {
  5665.     return &lang_sub_obj;
  5666. }
  5667.  
  5668. # Rewrite a single Java file.
  5669. sub lang_java_rewrite
  5670. {
  5671.     return LANG_SUBDIR;
  5672. }
  5673.  
  5674. # The lang_X_finish functions are called after all source file
  5675. # processing is done.  Each should handle defining rules for the
  5676. # language, etc.  A finish function is only called if a source file of
  5677. # the appropriate type has been seen.
  5678.  
  5679. sub lang_c_finish
  5680. {
  5681.     # Push all libobjs files onto de_ansi_files.  We actually only
  5682.     # push files which exist in the current directory, and which are
  5683.     # genuine source files.
  5684.     foreach my $file (keys %libsources)
  5685.     {
  5686.     if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
  5687.     {
  5688.         $de_ansi_files{$1} = ''
  5689.     }
  5690.     }
  5691.  
  5692.     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
  5693.     {
  5694.      # Make all _.c files depend on their corresponding .c files.
  5695.      my @objects;
  5696.      foreach my $base (sort keys %de_ansi_files)
  5697.      {
  5698.         # Each _.c file must depend on ansi2knr; otherwise it
  5699.         # might be used in a parallel build before it is built.
  5700.         # We need to support files in the srcdir and in the build
  5701.         # dir (because these files might be auto-generated.  But
  5702.         # we can't use $< -- some makes only define $< during a
  5703.         # suffix rule.
  5704.         my $ansfile = $de_ansi_files{$base} . $base . '.c';
  5705.          $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
  5706.                   . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
  5707.                   . '`if test -f $(srcdir)/' . $ansfile
  5708.                   . '; then echo $(srcdir)/' . $ansfile
  5709.                   . '; else echo ' . $ansfile . '; fi` '
  5710.                   . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
  5711.                   . '| $(ANSI2KNR) > $@'
  5712.                   # If ansi2knr fails then we shouldn't
  5713.                   # create the _.c file
  5714.                   . " || rm -f \$\@\n");
  5715.          push (@objects, $base . '_.$(OBJEXT)');
  5716.          push (@objects, $base . '_.lo')
  5717.           if variable_defined ('LIBTOOL');
  5718.      }
  5719.  
  5720.      # Make all _.o (and _.lo) files depend on ansi2knr.
  5721.      # Use a sneaky little hack to make it print nicely.
  5722.      &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
  5723.     }
  5724. }
  5725.  
  5726. # This is a yacc helper which is called whenever we have decided to
  5727. # compile a yacc file.
  5728. sub lang_yacc_target_hook
  5729. {
  5730.     my ($self, $aggregate, $output, $input) = @_;
  5731.  
  5732.     my $flag = $aggregate . "_YFLAGS";
  5733.     if ((variable_defined ($flag)
  5734.      && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
  5735.     || (variable_defined ('YFLAGS')
  5736.         && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
  5737.     {
  5738.     (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
  5739.     my $header = $output_base . '.h';
  5740.  
  5741.     # Found a `-d' that applies to the compilation of this file.
  5742.     # Add a dependency for the generated header file, and arrange
  5743.     # for that file to be included in the distribution.
  5744.     # FIXME: this fails for `nodist_*_SOURCES'.
  5745.     $output_rules .= ("${header}: $output\n"
  5746.               # Recover from removal of $header
  5747.               . "\t\@if test ! -f \$@; then \\\n"
  5748.               . "\t  rm -f $output; \\\n"
  5749.               . "\t  \$(MAKE) $output; \\\n"
  5750.               . "\telse :; fi\n");
  5751.     &push_dist_common ($header);
  5752.     # If the files are built in the build directory, then we want
  5753.     # to remove them with `make clean'.  If they are in srcdir
  5754.     # they shouldn't be touched.  However, we can't determine this
  5755.     # statically, and the GNU rules say that yacc/lex output files
  5756.     # should be removed by maintainer-clean.  So that's what we
  5757.     # do.
  5758.     $clean_files{$header} = MAINTAINER_CLEAN;
  5759.     }
  5760.     # Erase $OUTPUT on `make maintainer-clean' (by GNU standards).
  5761.     # See the comment above for $HEADER.
  5762.     $clean_files{$output} = MAINTAINER_CLEAN;
  5763. }
  5764.  
  5765. # This is a lex helper which is called whenever we have decided to
  5766. # compile a lex file.
  5767. sub lang_lex_target_hook
  5768. {
  5769.     my ($self, $aggregate, $output, $input) = @_;
  5770.     # If the files are built in the build directory, then we want to
  5771.     # remove them with `make clean'.  If they are in srcdir they
  5772.     # shouldn't be touched.  However, we can't determine this
  5773.     # statically, and the GNU rules say that yacc/lex output files
  5774.     # should be removed by maintainer-clean.  So that's what we do.
  5775.     $clean_files{$output} = MAINTAINER_CLEAN;
  5776. }
  5777.  
  5778. # This is a helper for both lex and yacc.
  5779. sub yacc_lex_finish_helper
  5780. {
  5781.     return if defined $language_scratch{'lex-yacc-done'};
  5782.     $language_scratch{'lex-yacc-done'} = 1;
  5783.  
  5784.     # If there is more than one distinct yacc (resp lex) source file
  5785.     # in a given directory, then the `ylwrap' program is required to
  5786.     # allow parallel builds to work correctly.  FIXME: for now, no
  5787.     # line number.
  5788.     require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
  5789.     if ($config_aux_dir_set_in_configure_in)
  5790.     {
  5791.     &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
  5792.     }
  5793.     else
  5794.     {
  5795.     &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
  5796.     }
  5797. }
  5798.  
  5799. sub lang_yacc_finish
  5800. {
  5801.   return if defined $language_scratch{'yacc-done'};
  5802.   $language_scratch{'yacc-done'} = 1;
  5803.  
  5804.   reject_var 'YACCFLAGS', "`YACCFLAGS' obsolete; use `YFLAGS' instead";
  5805.  
  5806.   &yacc_lex_finish_helper
  5807.     if count_files_for_language ('yacc') > 1;
  5808. }
  5809.  
  5810.  
  5811. sub lang_lex_finish
  5812. {
  5813.   return if defined $language_scratch{'lex-done'};
  5814.   $language_scratch{'lex-done'} = 1;
  5815.  
  5816.   &yacc_lex_finish_helper
  5817.     if count_files_for_language ('lex') > 1;
  5818. }
  5819.  
  5820.  
  5821. # Given a hash table of linker names, pick the name that has the most
  5822. # precedence.  This is lame, but something has to have global
  5823. # knowledge in order to eliminate the conflict.  Add more linkers as
  5824. # required.
  5825. sub resolve_linker
  5826. {
  5827.     my (%linkers) = @_;
  5828.  
  5829.     foreach my $l (qw(GCJLINK CXXLINK F77LINK OBJCLINK))
  5830.     {
  5831.     return $l if defined $linkers{$l};
  5832.     }
  5833.     return 'LINK';
  5834. }
  5835.  
  5836. # Called to indicate that an extension was used.
  5837. sub saw_extension
  5838. {
  5839.     my ($ext) = @_;
  5840.     if (! defined $extension_seen{$ext})
  5841.     {
  5842.     $extension_seen{$ext} = 1;
  5843.     }
  5844.     else
  5845.     {
  5846.     ++$extension_seen{$ext};
  5847.     }
  5848. }
  5849.  
  5850. # Return the number of files seen for a given language.  Knows about
  5851. # special cases we care about.  FIXME: this is hideous.  We need
  5852. # something that involves real language objects.  For instance yacc
  5853. # and yaccxx could both derive from a common yacc class which would
  5854. # know about the strange ylwrap requirement.  (Or better yet we could
  5855. # just not support legacy yacc!)
  5856. sub count_files_for_language
  5857. {
  5858.     my ($name) = @_;
  5859.  
  5860.     my @names;
  5861.     if ($name eq 'yacc' || $name eq 'yaccxx')
  5862.     {
  5863.     @names = ('yacc', 'yaccxx');
  5864.     }
  5865.     elsif ($name eq 'lex' || $name eq 'lexxx')
  5866.     {
  5867.     @names = ('lex', 'lexxx');
  5868.     }
  5869.     else
  5870.     {
  5871.     @names = ($name);
  5872.     }
  5873.  
  5874.     my $r = 0;
  5875.     foreach $name (@names)
  5876.     {
  5877.     my $lang = $languages{$name};
  5878.     foreach my $ext (@{$lang->extensions})
  5879.     {
  5880.         $r += $extension_seen{$ext}
  5881.             if defined $extension_seen{$ext};
  5882.     }
  5883.     }
  5884.  
  5885.     return $r
  5886. }
  5887.  
  5888. # Called to ask whether source files have been seen . If HEADERS is 1,
  5889. # headers can be included.
  5890. sub saw_sources_p
  5891. {
  5892.     my ($headers) = @_;
  5893.  
  5894.     # count all the sources
  5895.     my $count = 0;
  5896.     foreach my $val (values %extension_seen)
  5897.     {
  5898.     $count += $val;
  5899.     }
  5900.  
  5901.     if (!$headers)
  5902.     {
  5903.     $count -= count_files_for_language ('header');
  5904.     }
  5905.  
  5906.     return $count > 0;
  5907. }
  5908.  
  5909.  
  5910. # register_language (%ATTRIBUTE)
  5911. # ------------------------------
  5912. # Register a single language.
  5913. # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
  5914. sub register_language (%)
  5915. {
  5916.   my (%option) = @_;
  5917.  
  5918.   # Set the defaults.
  5919.   $option{'ansi'} = 0
  5920.     unless defined $option{'ansi'};
  5921.   $option{'autodep'} = 'no'
  5922.     unless defined $option{'autodep'};
  5923.   $option{'linker'} = ''
  5924.     unless defined $option{'linker'};
  5925.   $option{'flags'} = []
  5926.     unless defined $option{'flags'};
  5927.   $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
  5928.     unless defined $option{'output_extensions'};
  5929.  
  5930.   my $lang = new Language (%option);
  5931.  
  5932.   # Fill indexes.
  5933.   grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
  5934.   $languages{$lang->name} = $lang;
  5935.  
  5936.   # Update the pattern of known extensions.
  5937.   accept_extensions (@{$lang->extensions});
  5938.  
  5939.   # Upate the $suffix_rule map.
  5940.   foreach my $suffix (@{$lang->extensions})
  5941.     {
  5942.       foreach my $dest (&{$lang->output_extensions} ($suffix))
  5943.     {
  5944.       ®ister_suffix_rule ('internal', $suffix, $dest);
  5945.     }
  5946.     }
  5947. }
  5948.  
  5949. # derive_suffix ($EXT, $OBJ)
  5950. # --------------------------
  5951. # This function is used to find a path from a user-specified suffix $EXT
  5952. # to $OBJ or to some other suffix we recognize internally, eg `cc'.
  5953. sub derive_suffix ($$)
  5954. {
  5955.   my ($source_ext, $obj) = @_;
  5956.  
  5957.   while (! $extension_map{$source_ext}
  5958.      && $source_ext ne $obj
  5959.      && exists $suffix_rules->{$source_ext}
  5960.      && exists $suffix_rules->{$source_ext}{$obj})
  5961.     {
  5962.       $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
  5963.     }
  5964.  
  5965.   return $source_ext;
  5966. }
  5967.  
  5968.  
  5969. ################################################################
  5970.  
  5971. # Pretty-print something.  HEAD is what should be printed at the
  5972. # beginning of the first line, FILL is what should be printed at the
  5973. # beginning of every subsequent line.
  5974. sub pretty_print_internal
  5975. {
  5976.     my ($head, $fill, @values) = @_;
  5977.  
  5978.     my $column = length ($head);
  5979.     my $result = $head;
  5980.  
  5981.     # Fill length is number of characters.  However, each Tab
  5982.     # character counts for eight.  So we count the number of Tabs and
  5983.     # multiply by 7.
  5984.     my $fill_length = length ($fill);
  5985.     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
  5986.  
  5987.     foreach (@values)
  5988.     {
  5989.     # "71" because we also print a space.
  5990.     if ($column + length ($_) > 71)
  5991.     {
  5992.         $result .= " \\\n" . $fill;
  5993.         $column = $fill_length;
  5994.     }
  5995.     $result .= ' ' if $result =~ /\S\z/;
  5996.     $result .= $_;
  5997.     $column += length ($_) + 1;
  5998.     }
  5999.  
  6000.     $result .= "\n";
  6001.     return $result;
  6002. }
  6003.  
  6004. # Pretty-print something and append to output_vars.
  6005. sub pretty_print
  6006. {
  6007.     $output_vars .= &pretty_print_internal (@_);
  6008. }
  6009.  
  6010. # Pretty-print something and append to output_rules.
  6011. sub pretty_print_rule
  6012. {
  6013.     $output_rules .= &pretty_print_internal (@_);
  6014. }
  6015.  
  6016.  
  6017. ################################################################
  6018.  
  6019.  
  6020. # $STRING
  6021. # &conditional_string(@COND-STACK)
  6022. # --------------------------------
  6023. # Build a string which denotes the conditional in @COND-STACK.  Some
  6024. # simplifications are done: `TRUE' entries are elided, and any `FALSE'
  6025. # entry results in a return of `FALSE'.
  6026. sub conditional_string
  6027. {
  6028.   my (@stack) = @_;
  6029.  
  6030.   if (grep (/^FALSE$/, @stack))
  6031.     {
  6032.       return 'FALSE';
  6033.     }
  6034.   else
  6035.     {
  6036.       return join (' ', uniq sort grep (!/^TRUE$/, @stack));
  6037.     }
  6038. }
  6039.  
  6040.  
  6041. # $BOOLEAN
  6042. # &conditional_true_when ($COND, $WHEN)
  6043. # -------------------------------------
  6044. # See if a conditional is true.  Both arguments are conditional
  6045. # strings.  This returns true if the first conditional is true when
  6046. # the second conditional is true.
  6047. # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
  6048. # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
  6049. sub conditional_true_when ($$)
  6050. {
  6051.     my ($cond, $when) = @_;
  6052.  
  6053.     # Make a hash holding all the values from $WHEN.
  6054.     my %cond_vals = map { $_ => 1 } split (' ', $when);
  6055.  
  6056.     # Nothing is true when FALSE (not even FALSE itself, but it
  6057.     # shouldn't hurt if you decide to change that).
  6058.     return 0 if exists $cond_vals{'FALSE'};
  6059.  
  6060.     # Check each component of $cond, which looks `COND1 COND2'.
  6061.     foreach my $comp (split (' ', $cond))
  6062.     {
  6063.     # TRUE is always true.
  6064.     next if $comp eq 'TRUE';
  6065.     return 0 if ! defined $cond_vals{$comp};
  6066.     }
  6067.  
  6068.     return 1;
  6069. }
  6070.  
  6071.  
  6072. # $BOOLEAN
  6073. # &conditional_is_redundant ($COND, @WHENS)
  6074. # ----------------------------------------
  6075. # Determine whether $COND is redundant with respect to @WHENS.
  6076. #
  6077. # Returns true if $COND is true for any of the conditions in @WHENS.
  6078. #
  6079. # If there are no @WHENS, then behave as if @WHENS contained a single empty
  6080. # condition.
  6081. sub conditional_is_redundant ($@)
  6082. {
  6083.     my ($cond, @whens) = @_;
  6084.  
  6085.     @whens = ("") if @whens == 0;
  6086.  
  6087.     foreach my $when (@whens)
  6088.     {
  6089.     return 1 if conditional_true_when ($cond, $when);
  6090.     }
  6091.     return 0;
  6092. }
  6093.  
  6094.  
  6095. # $BOOLEAN
  6096. # &conditional_implies_any ($COND, @CONDS)
  6097. # ----------------------------------------
  6098. # Returns true iff $COND implies any of the conditions in @CONDS.
  6099. sub conditional_implies_any ($@)
  6100. {
  6101.     my ($cond, @conds) = @_;
  6102.  
  6103.     @conds = ("") if @conds == 0;
  6104.  
  6105.     foreach my $c (@conds)
  6106.     {
  6107.     return 1 if conditional_true_when ($c, $cond);
  6108.     }
  6109.     return 0;
  6110. }
  6111.  
  6112.  
  6113. # $NEGATION
  6114. # condition_negate ($COND)
  6115. # ------------------------
  6116. sub condition_negate ($)
  6117. {
  6118.     my ($cond) = @_;
  6119.  
  6120.     $cond =~ s/TRUE$/TRUEO/;
  6121.     $cond =~ s/FALSE$/TRUE/;
  6122.     $cond =~ s/TRUEO$/FALSE/;
  6123.  
  6124.     return $cond;
  6125. }
  6126.  
  6127.  
  6128. # Compare condition names.
  6129. # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
  6130. sub by_condition
  6131. {
  6132.     # Be careful we might be comparing `' or `#'.
  6133.     $a =~ /^(.*)_(TRUE|FALSE)$/;
  6134.     my ($aname, $abool) = ($1 || '', $2 || '');
  6135.     $b =~ /^(.*)_(TRUE|FALSE)$/;
  6136.     my ($bname, $bbool) = ($1 || '', $2 || '');
  6137.     return ($aname cmp $bname
  6138.         # Don't bother with IFs, given that TRUE is after FALSE
  6139.         # just cmp in the reverse order.
  6140.         || $bbool cmp $abool
  6141.         # Just in case...
  6142.         || $a cmp $b);
  6143. }
  6144.  
  6145.  
  6146. # &make_condition (@CONDITIONS)
  6147. # -----------------------------
  6148. # Transform a list of conditions (themselves can be an internal list
  6149. # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
  6150. # Make conditional (a pattern for AC_SUBST).
  6151. # Correctly returns the empty string when there are no conditions.
  6152. sub make_condition
  6153. {
  6154.     my $res = conditional_string (@_);
  6155.  
  6156.     # There are no conditions.
  6157.     if ($res eq '')
  6158.       {
  6159.     # Nothing to do.
  6160.       }
  6161.     # It's impossible.
  6162.     elsif ($res eq 'FALSE')
  6163.       {
  6164.     $res = '#';
  6165.       }
  6166.     # Build it.
  6167.     else
  6168.       {
  6169.     $res = '@' . $res . '@';
  6170.     $res =~ s/ /@@/g;
  6171.       }
  6172.  
  6173.     return $res;
  6174. }
  6175.  
  6176.  
  6177.  
  6178. ## ------------------------------ ##
  6179. ## Handling the condition stack.  ##
  6180. ## ------------------------------ ##
  6181.  
  6182.  
  6183. # $COND_STRING
  6184. # cond_stack_if ($NEGATE, $COND, $WHERE)
  6185. # --------------------------------------
  6186. sub cond_stack_if ($$$)
  6187. {
  6188.   my ($negate, $cond, $where) = @_;
  6189.  
  6190.   error $where, "$cond does not appear in AM_CONDITIONAL"
  6191.     if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
  6192.  
  6193.   $cond = "${cond}_TRUE"
  6194.     unless $cond =~ /^TRUE|FALSE$/;
  6195.   $cond = condition_negate ($cond)
  6196.     if $negate;
  6197.  
  6198.   push (@cond_stack, $cond);
  6199.  
  6200.   return conditional_string (@cond_stack);
  6201. }
  6202.  
  6203.  
  6204. # $COND_STRING
  6205. # cond_stack_else ($NEGATE, $COND, $WHERE)
  6206. # ----------------------------------------
  6207. sub cond_stack_else ($$$)
  6208. {
  6209.   my ($negate, $cond, $where) = @_;
  6210.  
  6211.   if (! @cond_stack)
  6212.     {
  6213.       error $where, "else without if";
  6214.       return;
  6215.     }
  6216.  
  6217.   $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
  6218.  
  6219.   # If $COND is given, check against it.
  6220.   if (defined $cond)
  6221.     {
  6222.       $cond = "${cond}_TRUE"
  6223.     unless $cond =~ /^TRUE|FALSE$/;
  6224.       $cond = condition_negate ($cond)
  6225.     if $negate;
  6226.  
  6227.       error ($where, "else reminder ($negate$cond) incompatible with "
  6228.          . "current conditional: $cond_stack[$#cond_stack]")
  6229.     if $cond_stack[$#cond_stack] ne $cond;
  6230.     }
  6231.  
  6232.   return conditional_string (@cond_stack);
  6233. }
  6234.  
  6235.  
  6236. # $COND_STRING
  6237. # cond_stack_endif ($NEGATE, $COND, $WHERE)
  6238. # -----------------------------------------
  6239. sub cond_stack_endif ($$$)
  6240. {
  6241.   my ($negate, $cond, $where) = @_;
  6242.   my $old_cond;
  6243.  
  6244.   if (! @cond_stack)
  6245.     {
  6246.       error $where, "endif without if: $negate$cond";
  6247.       return;
  6248.     }
  6249.  
  6250.  
  6251.   # If $COND is given, check against it.
  6252.   if (defined $cond)
  6253.     {
  6254.       $cond = "${cond}_TRUE"
  6255.     unless $cond =~ /^TRUE|FALSE$/;
  6256.       $cond = condition_negate ($cond)
  6257.     if $negate;
  6258.  
  6259.       error ($where, "endif reminder ($negate$cond) incompatible with "
  6260.          . "current conditional: $cond_stack[$#cond_stack]")
  6261.     if $cond_stack[$#cond_stack] ne $cond;
  6262.     }
  6263.  
  6264.   pop @cond_stack;
  6265.  
  6266.   return conditional_string (@cond_stack);
  6267. }
  6268.  
  6269.  
  6270.  
  6271.  
  6272.  
  6273. ## ------------------------ ##
  6274. ## Handling the variables.  ##
  6275. ## ------------------------ ##
  6276.  
  6277.  
  6278. # check_ambiguous_conditional ($VAR, $COND, $WHERE)
  6279. # -------------------------------------------------
  6280. # Check for an ambiguous conditional.  This is called when a variable
  6281. # is being defined conditionally.  If we already know about a
  6282. # definition that is true under the same conditions, then we have an
  6283. # ambiguity.
  6284. sub check_ambiguous_conditional ($$$)
  6285. {
  6286.   my ($var, $cond, $where) = @_;
  6287.   my ($message, $ambig_cond) =
  6288.     conditional_ambiguous_p ($var, $cond, keys %{$var_value{$var}});
  6289.   if ($message)
  6290.     {
  6291.       msg 'syntax', $where, "$message ...";
  6292.       msg_var ('syntax', $var, "... `$var' previously defined here.");
  6293.       verb (macro_dump ($var));
  6294.     }
  6295. }
  6296.  
  6297. # $STRING, $AMBIG_COND
  6298. # conditional_ambiguous_p ($WHAT, $COND, @CONDS)
  6299. # ----------------------------------------------
  6300. # Check for an ambiguous conditional.  Return an error message and
  6301. # the other condition involved if we have one, two empty strings otherwise.
  6302. #   WHAT:  the thing being defined
  6303. #   COND:  the condition under which it is being defined
  6304. #   CONDS: the conditions under which it had already been defined
  6305. sub conditional_ambiguous_p ($$@)
  6306. {
  6307.   my ($var, $cond, @conds) = @_;
  6308.   foreach my $vcond (@conds)
  6309.     {
  6310.       # Note that these rules doesn't consider the following
  6311.       # example as ambiguous.
  6312.       #
  6313.       #   if COND1
  6314.       #     FOO = foo
  6315.       #   endif
  6316.       #   if COND2
  6317.       #     FOO = bar
  6318.       #   endif
  6319.       #
  6320.       # It's up to the user to not define COND1 and COND2
  6321.       # simultaneously.
  6322.       my $message;
  6323.       if ($vcond eq $cond)
  6324.     {
  6325.       return ("$var multiply defined in condition $cond", $vcond);
  6326.     }
  6327.       elsif (&conditional_true_when ($vcond, $cond))
  6328.     {
  6329.       return ("$var was already defined in condition $vcond, "
  6330.           . "which implies condition $cond", $vcond);
  6331.     }
  6332.       elsif (&conditional_true_when ($cond, $vcond))
  6333.     {
  6334.       return ("$var was already defined in condition $vcond, "
  6335.            . "which is implied by condition $cond", $vcond);
  6336.     }
  6337.     }
  6338.   return ('', '');
  6339. }
  6340.  
  6341. # @MISSING_CONDS
  6342. # variable_not_always_defined_in_cond ($VAR, $COND)
  6343. # ---------------------------------------------
  6344. # Check whether $VAR is always defined for condition $COND.
  6345. # Return a list of conditions where the definition is missing.
  6346. #
  6347. # For instance, given
  6348. #
  6349. #   if COND1
  6350. #     if COND2
  6351. #       A = foo
  6352. #       D = d1
  6353. #     else
  6354. #       A = bar
  6355. #       D = d2
  6356. #     endif
  6357. #   else
  6358. #     D = d3
  6359. #   endif
  6360. #   if COND3
  6361. #     A = baz
  6362. #     B = mumble
  6363. #   endif
  6364. #   C = mumble
  6365. #
  6366. # we should have:
  6367. #   variable_not_always_defined_in_cond ('A', 'COND1_TRUE COND2_TRUE')
  6368. #     => ()
  6369. #   variable_not_always_defined_in_cond ('A', 'COND1_TRUE')
  6370. #     => ()
  6371. #   variable_not_always_defined_in_cond ('A', 'TRUE')
  6372. #     => ("COND1_FALSE COND2_FALSE COND3_FALSE",
  6373. #         "COND1_FALSE COND2_TRUE COND3_FALSE",
  6374. #         "COND1_TRUE COND2_FALSE COND3_FALSE",
  6375. #         "COND1_TRUE COND2_TRUE COND3_FALSE")
  6376. #   variable_not_always_defined_in_cond ('B', 'COND1_TRUE')
  6377. #     => ("COND3_FALSE")
  6378. #   variable_not_always_defined_in_cond ('C', 'COND1_TRUE')
  6379. #     => ()
  6380. #   variable_not_always_defined_in_cond ('D', 'TRUE')
  6381. #     => ()
  6382. #   variable_not_always_defined_in_cond ('Z', 'TRUE')
  6383. #     => ("TRUE")
  6384. #
  6385. sub variable_not_always_defined_in_cond ($$)
  6386. {
  6387.   my ($var, $cond) = @_;
  6388.  
  6389.   # It's easy to answer if the variable is not defined.
  6390.   return ("TRUE",) unless exists $var_value{$var};
  6391.  
  6392.   # How does it work?  Let's take the second example:
  6393.   #
  6394.   #   variable_not_always_defined_in_cond ('A', 'COND1_TRUE')
  6395.   #
  6396.   # (1) First, we get the list of conditions where A is defined:
  6397.   #
  6398.   #   ("COND1_TRUE COND2_TRUE", "COND1_TRUE COND2_FALSE", "COND3_TRUE")
  6399.   #
  6400.   # (2) Then we generate the set of inverted conditions:
  6401.   #
  6402.   #   ("COND1_FALSE COND2_TRUE COND3_FALSE",
  6403.   #    "COND1_FALSE COND2_FALSE COND3_FALSE")
  6404.   #
  6405.   # (3) Finally we remove these conditions which are not implied by
  6406.   #     COND1_TRUE.  This yields an empty list and we are done.
  6407.  
  6408.   my @res = ();
  6409.   my @cond_defs = keys %{$var_value{$var}}; # (1)
  6410.   foreach my $icond (invert_conditions (@cond_defs)) # (2)
  6411.     {
  6412.       prog_error "invert_conditions returned an input condition"
  6413.     if exists $var_value{$var}{$icond};
  6414.  
  6415.       push @res, $icond
  6416.     if (conditional_true_when ($cond, $icond)); # (3)
  6417.     }
  6418.   return @res;
  6419. }
  6420.  
  6421. # ¯o_define($VAR, $OWNER, $TYPE, $COND, $VALUE, $WHERE)
  6422. # -------------------------------------------------------------
  6423. # The $VAR can go from Automake to user, but not the converse.
  6424. sub macro_define ($$$$$$)
  6425. {
  6426.   my ($var, $owner, $type, $cond, $value, $where) = @_;
  6427.  
  6428.   # We will adjust the owner of this variable unless told otherwise.
  6429.   my $adjust_owner = 1;
  6430.  
  6431.   error $where, "bad characters in variable name `$var'"
  6432.     if $var !~ /$MACRO_PATTERN/o;
  6433.  
  6434.   # `:='-style assignments are not acknowledged by POSIX.  Moreover it
  6435.   # has multiple meanings.  In GNU make or BSD make it means "assign
  6436.   # with immediate expansion", while in OSF make it is used for
  6437.   # conditional assignments.
  6438.   msg ('portability', $where, "`:='-style assignments are not portable")
  6439.     if $type eq ':';
  6440.  
  6441.   check_variable_expansions ($value, $where);
  6442.  
  6443.   $cond ||= 'TRUE';
  6444.  
  6445.   # An Automake variable must be consistently defined with the same
  6446.   # sign by Automake.  A user variable must be set by either `=' or
  6447.   # `:=', and later promoted to `+='.
  6448.   if ($owner == VAR_AUTOMAKE)
  6449.     {
  6450.       if (exists $var_type{$var}
  6451.       && exists $var_type{$var}{$cond}
  6452.       && $var_type{$var}{$cond} ne $type)
  6453.     {
  6454.       error ($where, "$var was set with `$var_type{$var}=' "
  6455.          . "and is now set with `$type='");
  6456.     }
  6457.     }
  6458.   else
  6459.     {
  6460.       if (!exists $var_type{$var} && $type eq '+')
  6461.     {
  6462.       error $where, "$var must be set with `=' before using `+='";
  6463.     }
  6464.     }
  6465.   $var_type{$var}{$cond} = $type;
  6466.  
  6467.   # Differentiate assignment types.
  6468.  
  6469.   # 1. append (+=) to a variable defined for current condition
  6470.   if ($type eq '+' && exists $var_value{$var}{$cond})
  6471.     {
  6472.       if (chomp $var_value{$var}{$cond})
  6473.     {
  6474.       # Insert a backslash before a trailing newline.
  6475.       $var_value{$var}{$cond} .= "\\\n";
  6476.     }
  6477.       elsif ($var_value{$var}{$cond})
  6478.     {
  6479.       # Insert a separator.
  6480.       $var_value{$var}{$cond} .= ' ';
  6481.     }
  6482.        $var_value{$var}{$cond} .= $value;
  6483.     }
  6484.   # 2. append (+=) to a variable defined for *another* condition
  6485.   elsif ($type eq '+' && keys %{$var_value{$var}})
  6486.     {
  6487.       # * Generally, $cond is not TRUE.  For instance:
  6488.       #     FOO = foo
  6489.       #     if COND
  6490.       #       FOO += bar
  6491.       #     endif
  6492.       #   In this case, we declare an helper variable conditionally,
  6493.       #   and append it to FOO:
  6494.       #     FOO = foo $(am__append_1)
  6495.       #     @COND_TRUE@am__append_1 = bar
  6496.       #   Of course if FOO is defined under several conditions, we add
  6497.       #   $(am__append_1) to each definitions.
  6498.       #
  6499.       # * If $cond is TRUE, we don't need the helper variable.  E.g., in
  6500.       #     if COND1
  6501.       #       FOO = foo1
  6502.       #     else
  6503.       #       FOO = foo2
  6504.       #     endif
  6505.       #     FOO += bar
  6506.       #   we can add bar directly to all definition of FOO, and output
  6507.       #     @COND_TRUE@FOO = foo1 bar
  6508.       #     @COND_FALSE@FOO = foo2 bar
  6509.  
  6510.       # Do we need an helper variable?
  6511.       if ($cond ne 'TRUE')
  6512.         {
  6513.         # Does the helper variable already exists?
  6514.         my $key = "$var:$cond";
  6515.         if (exists $appendvar{$key})
  6516.           {
  6517.         # Yes, let's simply append to it.
  6518.         $var = $appendvar{$key};
  6519.         $owner = VAR_AUTOMAKE;
  6520.           }
  6521.         else
  6522.           {
  6523.         # No, create it.
  6524.         my $num = 1 + keys (%appendvar);
  6525.         my $hvar = "am__append_$num";
  6526.         $appendvar{$key} = $hvar;
  6527.         ¯o_define ($hvar, VAR_AUTOMAKE, '+',
  6528.                    $cond, $value, $where);
  6529.         push @var_list, $hvar;
  6530.         # Now HVAR is to be added to VAR.
  6531.         $value = "\$($hvar)";
  6532.           }
  6533.     }
  6534.  
  6535.       # Add VALUE to all definitions of VAR.
  6536.       foreach my $vcond (keys %{$var_value{$var}})
  6537.         {
  6538.       # We have a bit of error detection to do here.
  6539.       # This:
  6540.       #   if COND1
  6541.       #     X = Y
  6542.       #   endif
  6543.       #   X += Z
  6544.       # should be rejected because X is not defined for all conditions
  6545.       # where `+=' applies.
  6546.       my @undef_cond = variable_not_always_defined_in_cond $var, $cond;
  6547.       if (@undef_cond != 0)
  6548.         {
  6549.           error ($where,
  6550.              "Cannot apply `+=' because `$var' is not defined "
  6551.              . "in\nthe following conditions:\n  "
  6552.              . join ("\n  ", @undef_cond)
  6553.              . "\nEither define `$var' in these conditions,"
  6554.              . " or use\n`+=' in the same conditions as"
  6555.              . " the definitions.");
  6556.         }
  6557.       else
  6558.         {
  6559.           ¯o_define ($var, $owner, '+', $vcond, $value, $where);
  6560.         }
  6561.     }
  6562.       # Don't adjust the owner.  The above ¯o_define did it in the
  6563.       # right conditions.
  6564.       $adjust_owner = 0;
  6565.     }
  6566.   # 3. first assignment (=, :=, or +=)
  6567.   else
  6568.     {
  6569.       # If Automake tries to override a value specified by the user,
  6570.       # just don't let it do.
  6571.       if (exists $var_value{$var}{$cond}
  6572.       && $var_owner{$var}{$cond} != VAR_AUTOMAKE
  6573.       && $owner == VAR_AUTOMAKE)
  6574.     {
  6575.       verb ("refusing to override the user definition of:\n"
  6576.         . macro_dump ($var)
  6577.         ."with `$cond' => `$value'");
  6578.     }
  6579.       else
  6580.     {
  6581.       # There must be no previous value unless the user is redefining
  6582.       # an Automake variable or an AC_SUBST variable for an existing
  6583.       # condition.
  6584.       check_ambiguous_conditional ($var, $cond, $where)
  6585.         unless (exists $var_owner{$var}{$cond}
  6586.             && (($var_owner{$var}{$cond} == VAR_AUTOMAKE
  6587.              && $owner != VAR_AUTOMAKE)
  6588.             || $var_owner{$var}{$cond} == VAR_CONFIGURE));
  6589.  
  6590.       $var_value{$var}{$cond} = $value;
  6591.       # Assignments to a macro set its location.  We don't adjust
  6592.       # locations for `+='.  Ideally I suppose we would associate
  6593.       # line numbers with random bits of text.
  6594.       $var_location{$var}{$cond} = $where;
  6595.     }
  6596.     }
  6597.  
  6598.   # The owner of a variable can only increase, because an Automake
  6599.   # variable can be given to the user, but not the converse.
  6600.   if ($adjust_owner &&
  6601.       (! exists $var_owner{$var}{$cond}
  6602.        || $owner > $var_owner{$var}{$cond}))
  6603.     {
  6604.       $var_owner{$var}{$cond} = $owner;
  6605.       # Always adjust the location when the owner changes (even for
  6606.       # `+=' statements).  The risk otherwise is to warn about
  6607.       # a VAR_MAKEFILE variable and locate it in configure.ac...
  6608.       $var_location{$var}{$cond} = $where;
  6609.     }
  6610.  
  6611.   # Call var_VAR_trigger if it's defined.
  6612.   # This hook helps to update some internal state *while*
  6613.   # parsing the file.  For instance the handling of SUFFIXES
  6614.   # requires this (see var_SUFFIXES_trigger).
  6615.   my $var_trigger = "var_${var}_trigger";
  6616.   &$var_trigger($type, $value) if defined &$var_trigger;
  6617. }
  6618.  
  6619.  
  6620. # ¯o_delete ($VAR, [@CONDS])
  6621. # ------------------------------
  6622. # Forget about $VAR under the conditions @CONDS, or completely if
  6623. # @CONDS is empty.
  6624. sub macro_delete ($@)
  6625. {
  6626.   my ($var, @conds) = @_;
  6627.  
  6628.   if (!@conds)
  6629.     {
  6630.       delete $var_value{$var};
  6631.       delete $var_location{$var};
  6632.       delete $var_owner{$var};
  6633.       delete $var_comment{$var};
  6634.       delete $var_type{$var};
  6635.     }
  6636.   else
  6637.     {
  6638.       foreach my $cond (@conds)
  6639.     {
  6640.       delete $var_value{$var}{$cond};
  6641.       delete $var_location{$var}{$cond};
  6642.       delete $var_owner{$var}{$cond};
  6643.       delete $var_comment{$var}{$cond};
  6644.       delete $var_type{$var}{$cond};
  6645.     }
  6646.     }
  6647. }
  6648.  
  6649.  
  6650. # ¯o_dump ($VAR)
  6651. # ------------------
  6652. sub macro_dump ($)
  6653. {
  6654.   my ($var) = @_;
  6655.   my $text = '';
  6656.  
  6657.   if (!exists $var_value{$var})
  6658.     {
  6659.       $text = "  $var does not exist\n";
  6660.     }
  6661.   else
  6662.     {
  6663.       $text .= "  $var $var_type{$var}=\n  {\n";
  6664.       foreach my $vcond (sort by_condition keys %{$var_value{$var}})
  6665.     {
  6666.       prog_error ("`$var' is a key in \$var_value, "
  6667.               . "but not in \$var_owner\n")
  6668.         unless exists $var_owner{$var}{$vcond};
  6669.  
  6670.       my $var_owner;
  6671.       if ($var_owner{$var}{$vcond} == VAR_AUTOMAKE)
  6672.         {
  6673.           $var_owner = 'Automake';
  6674.         }
  6675.       elsif ($var_owner{$var}{$vcond} == VAR_CONFIGURE)
  6676.         {
  6677.           $var_owner = 'Configure';
  6678.         }
  6679.       elsif ($var_owner{$var}{$vcond} == VAR_MAKEFILE)
  6680.         {
  6681.           $var_owner = 'Makefile';
  6682.         }
  6683.       else
  6684.         {
  6685.           prog_error ("unexpected value for `\$var_owner{$var}{$vcond}': "
  6686.               . $var_owner{$var}{$vcond})
  6687.         unless defined $var_owner;
  6688.         }
  6689.  
  6690.       my $where = (defined $var_location{$var}{$vcond}
  6691.                ? $var_location{$var}{$vcond} : "undefined");
  6692.       $text .= "$var_comment{$var}{$vcond}"
  6693.         if exists $var_comment{$var}{$vcond};
  6694.       $text .= "    $vcond => $var_value{$var}{$vcond}\n";
  6695.     }
  6696.       $text .= "  }\n";
  6697.     }
  6698.   return $text;
  6699. }
  6700.  
  6701.  
  6702. # ¯os_dump ()
  6703. # ---------------
  6704. sub macros_dump ()
  6705. {
  6706.   my ($var) = @_;
  6707.  
  6708.   my $text = "%var_value =\n{\n";
  6709.   foreach my $var (sort (keys %var_value))
  6710.     {
  6711.       $text .= macro_dump ($var);
  6712.     }
  6713.   $text .= "}\n";
  6714.   return $text;
  6715. }
  6716.  
  6717.  
  6718. # $BOOLEAN
  6719. # variable_defined ($VAR, [$COND])
  6720. # ---------------------------------
  6721. # See if a variable exists.  $VAR is the variable name, and $COND is
  6722. # the condition which we should check.  If no condition is given, we
  6723. # currently return true if the variable is defined under any
  6724. # condition.
  6725. sub variable_defined ($;$)
  6726. {
  6727.     my ($var, $cond) = @_;
  6728.  
  6729.     if (! exists $var_value{$var}
  6730.     || (defined $cond && ! exists $var_value{$var}{$cond}))
  6731.       {
  6732.     # VAR is not defined.
  6733.  
  6734.     # Check there is no target defined with the name of the
  6735.     # variable we check.
  6736.  
  6737.     # adl> I'm wondering if this error still makes any sense today. I
  6738.     # adl> guess it was because targets and variables used to share
  6739.     # adl> the same namespace in older versions of Automake?
  6740.     # tom> While what you say is definitely part of it, I think it
  6741.     # tom> might also have been due to someone making a "spelling error"
  6742.     # tom> -- writing "foo:..." instead of "foo = ...".
  6743.     # tom> I'm not sure whether it is really worth diagnosing
  6744.     # tom> this sort of problem.  In the old days I used to add warnings
  6745.     # tom> and errors like this pretty randomly, based on bug reports I
  6746.     # tom> got.  But there's a plausible argument that I was trying
  6747.     # tom> too hard to prevent people from making mistakes.
  6748.     if (exists $targets{$var}
  6749.         && (! defined $cond || exists $targets{$var}{$cond}))
  6750.       {
  6751.         for my $tcond ($cond || keys %{$targets{$var}})
  6752.           {
  6753.         prog_error ("\$targets{$var}{$tcond} exists but "
  6754.                 . "\$target_owner doesn't")
  6755.           unless exists $target_owner{$var}{$tcond};
  6756.         # Diagnose the first user target encountered, if any.
  6757.         # Restricting this test to user targets allows Automake
  6758.         # to create rules for things like `bin_PROGRAMS = LDADD'.
  6759.         if ($target_owner{$var}{$tcond} == TARGET_USER)
  6760.           {
  6761.             msg_cond_target ('syntax', $tcond, $var,
  6762.                      "`$var' is a target; "
  6763.                      . "expected a variable");
  6764.             return 0;
  6765.           }
  6766.           }
  6767.       }
  6768.     return 0;
  6769.       }
  6770.  
  6771.     # Even a var_value examination is good enough for us.  FIXME:
  6772.     # really should maintain examined status on a per-condition basis.
  6773.     $content_seen{$var} = 1;
  6774.     return 1;
  6775. }
  6776.  
  6777.  
  6778. # $BOOLEAN
  6779. # variable_assert ($VAR, $WHERE)
  6780. # ------------------------------
  6781. # Make sure a variable exists.  $VAR is the variable name, and $WHERE
  6782. # is the name of a macro which refers to $VAR.
  6783. sub variable_assert ($$)
  6784. {
  6785.   my ($var, $where) = @_;
  6786.  
  6787.   return 1
  6788.     if variable_defined $var;
  6789.  
  6790.   require_variables ($where, "variable `$var' is used", 'TRUE', $var);
  6791.  
  6792.   return 0;
  6793. }
  6794.  
  6795. # Mark a variable as examined.
  6796. sub examine_variable
  6797. {
  6798.   my ($var) = @_;
  6799.   variable_defined ($var);
  6800. }
  6801.  
  6802.  
  6803. # &variable_conditions_recursive ($VAR)
  6804. # -------------------------------------
  6805. # Return the set of conditions for which a variable is defined.
  6806.  
  6807. # If the variable is not defined conditionally, and is not defined in
  6808. # terms of any variables which are defined conditionally, then this
  6809. # returns the empty list.
  6810.  
  6811. # If the variable is defined conditionally, but is not defined in
  6812. # terms of any variables which are defined conditionally, then this
  6813. # returns the list of conditions for which the variable is defined.
  6814.  
  6815. # If the variable is defined in terms of any variables which are
  6816. # defined conditionally, then this returns a full set of permutations
  6817. # of the subvariable conditions.  For example, if the variable is
  6818. # defined in terms of a variable which is defined for COND_TRUE,
  6819. # then this returns both COND_TRUE and COND_FALSE.  This is
  6820. # because we will need to define the variable under both conditions.
  6821. sub variable_conditions_recursive ($)
  6822. {
  6823.     my ($var) = @_;
  6824.  
  6825.     %vars_scanned = ();
  6826.  
  6827.     my @new_conds = variable_conditions_recursive_sub ($var, '');
  6828.  
  6829.     # Now we want to return all permutations of the subvariable
  6830.     # conditions.
  6831.     my %allconds = ();
  6832.     foreach my $item (@new_conds)
  6833.     {
  6834.     foreach (split (' ', $item))
  6835.     {
  6836.         s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
  6837.         $allconds{$_} = 1;
  6838.     }
  6839.     }
  6840.     @new_conds = variable_conditions_permutations (sort keys %allconds);
  6841.  
  6842.     my %uniquify;
  6843.     foreach my $cond (@new_conds)
  6844.     {
  6845.     my $reduce = variable_conditions_reduce (split (' ', $cond));
  6846.         next
  6847.         if $reduce eq 'FALSE';
  6848.     $uniquify{$cond} = 1;
  6849.     }
  6850.  
  6851.     # Note we cannot just do `return sort keys %uniquify', because this
  6852.     # function is sometimes used in a scalar context.
  6853.     my @uniq_list = sort by_condition keys %uniquify;
  6854.     return @uniq_list;
  6855. }
  6856.  
  6857.  
  6858. # @CONDS
  6859. # variable_conditions ($VAR)
  6860. # --------------------------
  6861. # Get the list of conditions that a variable is defined with, without
  6862. # recursing through the conditions of any subvariables.
  6863. # Argument is $VAR: the variable to get the conditions of.
  6864. # Returns the list of conditions.
  6865. sub variable_conditions ($)
  6866. {
  6867.     my ($var) = @_;
  6868.     my @conds = keys %{$var_value{$var}};
  6869.     return sort by_condition @conds;
  6870. }
  6871.  
  6872.  
  6873. # $BOOLEAN
  6874. # &variable_conditionally_defined ($VAR)
  6875. # --------------------------------------
  6876. sub variable_conditionally_defined ($)
  6877. {
  6878.     my ($var) = @_;
  6879.     foreach my $cond (variable_conditions_recursive ($var))
  6880.       {
  6881.     return 1
  6882.       unless $cond =~ /^TRUE|FALSE$/;
  6883.       }
  6884.     return 0;
  6885. }
  6886.  
  6887. # @LIST
  6888. # &scan_variable_expansions ($TEXT)
  6889. # ---------------------------------
  6890. # Return the list of variable names expanded in $TEXT.
  6891. # Note that unlike some other functions, $TEXT is not split
  6892. # on spaces before we check for subvariables.
  6893. sub scan_variable_expansions ($)
  6894. {
  6895.   my ($text) = @_;
  6896.   my @result = ();
  6897.  
  6898.   # Strip comments.
  6899.   $text =~ s/#.*$//;
  6900.  
  6901.   # Record each use of ${stuff} or $(stuff) that does not follow a $.
  6902.   while ($text =~ /(?<!\$)\$(?:\{([^\}]*)\}|\(([^\)]*)\))/g)
  6903.     {
  6904.       my $var = $1 || $2;
  6905.       # The occurrence may look like $(string1[:subst1=[subst2]]) but
  6906.       # we want only `string1'.
  6907.       $var =~ s/:[^:=]*=[^=]*$//;
  6908.       push @result, $var;
  6909.     }
  6910.  
  6911.   return @result;
  6912. }
  6913.  
  6914. # &check_variable_expansions ($TEXT, $WHERE)
  6915. # ------------------------------------------
  6916. # Check variable expansions in $TEXT and warn about any name that
  6917. # does not conform to POSIX.  $WHERE is the location of $TEXT for
  6918. # the error message.
  6919. sub check_variable_expansions ($$)
  6920. {
  6921.   my ($text, $where) = @_;
  6922.   # Catch expansion of variables whose name does not conform to POSIX.
  6923.   foreach my $var (scan_variable_expansions ($text))
  6924.     {
  6925.       if ($var !~ /$MACRO_PATTERN/)
  6926.     {
  6927.       # If the variable name contains a space, it's likely
  6928.       # to be a GNU make extension (such as $(addsuffix ...)).
  6929.       # Mention this in the diagnostic.
  6930.       my $gnuext = "";
  6931.       $gnuext = "\n(probably a GNU make extension)" if $var =~ / /;
  6932.       msg ('portability', $where,
  6933.            "$var: non-POSIX variable name$gnuext");
  6934.     }
  6935.     }
  6936. }
  6937.  
  6938. # &variable_conditions_recursive_sub ($VAR, $PARENT)
  6939. # -------------------------------------------------------
  6940. # A subroutine of variable_conditions_recursive.  This returns all the
  6941. # conditions of $VAR, including those of any sub-variables.
  6942. sub variable_conditions_recursive_sub
  6943. {
  6944.     my ($var, $parent) = @_;
  6945.     my @new_conds = ();
  6946.  
  6947.     if (defined $vars_scanned{$var})
  6948.     {
  6949.         err_var $parent, "variable `$var' recursively defined";
  6950.     return ();
  6951.     }
  6952.     $vars_scanned{$var} = 1;
  6953.  
  6954.     my @this_conds = ();
  6955.     # Examine every condition under which $VAR is defined.
  6956.     foreach my $vcond (keys %{$var_value{$var}})
  6957.     {
  6958.       push (@this_conds, $vcond);
  6959.  
  6960.       # If $VAR references some other variable, then compute the
  6961.       # conditions for that subvariable.
  6962.       my @subvar_conds = ();
  6963.       foreach my $varname (scan_variable_expansions $var_value{$var}{$vcond})
  6964.     {
  6965.       if ($varname =~ /$SUBST_REF_PATTERN/o)
  6966.         {
  6967.           $varname = $1;
  6968.         }
  6969.  
  6970.       # Here we compute all the conditions under which the
  6971.       # subvariable is defined.  Then we go through and add
  6972.       # $VCOND to each.
  6973.       my @svc = variable_conditions_recursive_sub ($varname, $var);
  6974.       foreach my $item (@svc)
  6975.         {
  6976.           my $val = conditional_string ($vcond, split (' ', $item));
  6977.           $val ||= 'TRUE';
  6978.           push (@subvar_conds, $val);
  6979.         }
  6980.     }
  6981.  
  6982.       # If there are no conditional subvariables, then we want to
  6983.       # return this condition.  Otherwise, we want to return the
  6984.       # permutations of the subvariables, taking into account the
  6985.       # conditions of $VAR.
  6986.       if (! @subvar_conds)
  6987.     {
  6988.       push (@new_conds, $vcond);
  6989.     }
  6990.       else
  6991.     {
  6992.       push (@new_conds, variable_conditions_reduce (@subvar_conds));
  6993.     }
  6994.     }
  6995.  
  6996.     # Unset our entry in vars_scanned.  We only care about recursive
  6997.     # definitions.
  6998.     delete $vars_scanned{$var};
  6999.  
  7000.     # If we are being called on behalf of another variable, we need to
  7001.     # return all possible permutations of the conditions.  We have
  7002.     # already handled everything in @this_conds along with their
  7003.     # subvariables.  We now need to add any permutations that are not
  7004.     # in @this_conds.
  7005.     foreach my $this_cond (@this_conds)
  7006.     {
  7007.     my @perms =
  7008.         variable_conditions_permutations (split (' ', $this_cond));
  7009.     foreach my $perm (@perms)
  7010.     {
  7011.         my $ok = 1;
  7012.         foreach my $scan (@this_conds)
  7013.         {
  7014.         if (&conditional_true_when ($perm, $scan)
  7015.             || &conditional_true_when ($scan, $perm))
  7016.         {
  7017.             $ok = 0;
  7018.             last;
  7019.         }
  7020.         }
  7021.         next if ! $ok;
  7022.  
  7023.         # This permutation was not already handled, and is valid
  7024.         # for the parents.
  7025.         push (@new_conds, $perm);
  7026.     }
  7027.     }
  7028.  
  7029.     return @new_conds;
  7030. }
  7031.  
  7032.  
  7033. # Filter a list of conditionals so that only the exclusive ones are
  7034. # retained.  For example, if both `COND1_TRUE COND2_TRUE' and
  7035. # `COND1_TRUE' are in the list, discard the latter.
  7036. # If the list is empty, return TRUE
  7037. sub variable_conditions_reduce
  7038. {
  7039.     my (@conds) = @_;
  7040.     my @ret = ();
  7041.     my $cond;
  7042.     while(@conds > 0)
  7043.     {
  7044.     $cond = shift(@conds);
  7045.  
  7046.         # FALSE is absorbent.
  7047.     return 'FALSE'
  7048.       if $cond eq 'FALSE';
  7049.  
  7050.     if (!conditional_is_redundant ($cond, @ret, @conds))
  7051.       {
  7052.         push (@ret, $cond);
  7053.       }
  7054.     }
  7055.  
  7056.     return "TRUE" if @ret == 0;
  7057.     return @ret;
  7058. }
  7059.  
  7060. # @CONDS
  7061. # invert_conditions (@CONDS)
  7062. # --------------------------
  7063. # Invert a list of conditionals.  Returns a set of conditionals which
  7064. # are never true for any of the input conditionals, and when taken
  7065. # together with the input conditionals cover all possible cases.
  7066. #
  7067. # For example:
  7068. #   invert_conditions("A_TRUE B_TRUE", "A_FALSE B_FALSE")
  7069. #     => ("A_FALSE B_TRUE", "A_TRUE B_FALSE")
  7070. #
  7071. #   invert_conditions("A_TRUE B_TRUE", "A_TRUE B_FALSE", "A_FALSE")
  7072. #     => ()
  7073. sub invert_conditions
  7074. {
  7075.     my (@conds) = @_;
  7076.  
  7077.     my @notconds = ();
  7078.  
  7079.     # Generate all permutation for all inputs.
  7080.     my @perm =
  7081.     map { variable_conditions_permutations (split(' ', $_)); } @conds;
  7082.     # Remove redundant conditions.
  7083.     @perm = variable_conditions_reduce @perm;
  7084.  
  7085.     # Now remove all conditions which imply one of the input conditions.
  7086.     foreach my $perm (@perm)
  7087.     {
  7088.     push @notconds, $perm
  7089.         if ! conditional_implies_any ($perm, @conds);
  7090.     }
  7091.     return @notconds;
  7092. }
  7093.  
  7094. # Return a list of permutations of a conditional string.
  7095. # (But never output FALSE conditions, they are useless.)
  7096. #
  7097. # Examples:
  7098. #   variable_conditions_permutations ("FOO_FALSE", "BAR_TRUE")
  7099. #     => ("FOO_FALSE BAR_FALSE",
  7100. #         "FOO_FALSE BAR_TRUE",
  7101. #         "FOO_TRUE BAR_FALSE",
  7102. #         "FOO_TRUE BAR_TRUE")
  7103. #   variable_conditions_permutations ("FOO_FALSE", "TRUE")
  7104. #     => ("FOO_FALSE TRUE",
  7105. #         "FOO_TRUE TRUE")
  7106. #   variable_conditions_permutations ("TRUE")
  7107. #     => ("TRUE")
  7108. #   variable_conditions_permutations ("FALSE")
  7109. #     => ("TRUE")
  7110. sub variable_conditions_permutations
  7111. {
  7112.     my (@comps) = @_;
  7113.     return ()
  7114.     if ! @comps;
  7115.     my $comp = shift (@comps);
  7116.     return variable_conditions_permutations (@comps)
  7117.     if $comp eq '';
  7118.     my $neg = condition_negate ($comp);
  7119.  
  7120.     my @ret;
  7121.     foreach my $sub (variable_conditions_permutations (@comps))
  7122.     {
  7123.     push (@ret, "$comp $sub") if $comp ne 'FALSE';
  7124.     push (@ret, "$neg $sub") if $neg ne 'FALSE';
  7125.     }
  7126.     if (! @ret)
  7127.     {
  7128.     push (@ret, $comp) if $comp ne 'FALSE';
  7129.     push (@ret, $neg) if $neg ne 'FALSE';
  7130.     }
  7131.     return @ret;
  7132. }
  7133.  
  7134.  
  7135. # $BOOL
  7136. # &check_variable_defined_unconditionally($VAR, $PARENT)
  7137. # ------------------------------------------------------
  7138. # Warn if a variable is conditionally defined.  This is called if we
  7139. # are using the value of a variable.
  7140. sub check_variable_defined_unconditionally ($$)
  7141. {
  7142.   my ($var, $parent) = @_;
  7143.   foreach my $cond (keys %{$var_value{$var}})
  7144.     {
  7145.       next
  7146.     if $cond =~ /^TRUE|FALSE$/;
  7147.  
  7148.       if ($parent)
  7149.     {
  7150.       msg_var ('unsupported', $parent,
  7151.            "automake does not support conditional definition of "
  7152.            . "$var in $parent");
  7153.     }
  7154.       else
  7155.     {
  7156.       msg_var ('unsupported', $var,
  7157.            "automake does not support $var being defined "
  7158.            . "conditionally");
  7159.     }
  7160.     }
  7161. }
  7162.  
  7163.  
  7164. # Get the TRUE value of a variable, warn if the variable is
  7165. # conditionally defined.
  7166. sub variable_value
  7167. {
  7168.     my ($var) = @_;
  7169.     &check_variable_defined_unconditionally ($var);
  7170.     return $var_value{$var}{'TRUE'};
  7171. }
  7172.  
  7173.  
  7174. # @VALUES
  7175. # &value_to_list ($VAR, $VAL, $COND)
  7176. # ----------------------------------
  7177. # Convert a variable value to a list, split as whitespace.  This will
  7178. # recursively follow $(...) and ${...} inclusions.  It preserves @...@
  7179. # substitutions.
  7180. #
  7181. # If COND is 'all', then all values under all conditions should be
  7182. # returned; if COND is a particular condition (all conditions are
  7183. # surrounded by @...@) then only the value for that condition should
  7184. # be returned; otherwise, warn if VAR is conditionally defined.
  7185. # SCANNED is a global hash listing whose keys are all the variables
  7186. # already scanned; it is an error to rescan a variable.
  7187. sub value_to_list ($$$)
  7188. {
  7189.     my ($var, $val, $cond) = @_;
  7190.     my @result;
  7191.  
  7192.     # Strip backslashes
  7193.     $val =~ s/\\(\n|$)/ /g;
  7194.  
  7195.     foreach (split (' ', $val))
  7196.     {
  7197.     # If a comment seen, just leave.
  7198.     last if /^#/;
  7199.  
  7200.     # Handle variable substitutions.
  7201.     if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
  7202.     {
  7203.         my $varname = $1;
  7204.  
  7205.         # If the user uses a losing variable name, just ignore it.
  7206.         # This isn't ideal, but people have requested it.
  7207.         next if ($varname =~ /\@.*\@/);
  7208.  
  7209.         my ($from, $to);
  7210.         my @temp_list;
  7211.         if ($varname =~ /$SUBST_REF_PATTERN/o)
  7212.         {
  7213.         $varname = $1;
  7214.         $to = $3;
  7215.         $from = quotemeta $2;
  7216.         }
  7217.  
  7218.         # Find the value.
  7219.         @temp_list =
  7220.           variable_value_as_list_recursive_worker ($1, $cond, $var);
  7221.  
  7222.         # Now rewrite the value if appropriate.
  7223.         if (defined $from)
  7224.         {
  7225.         grep (s/$from$/$to/, @temp_list);
  7226.         }
  7227.  
  7228.         push (@result, @temp_list);
  7229.     }
  7230.     else
  7231.     {
  7232.         push (@result, $_);
  7233.     }
  7234.     }
  7235.  
  7236.     return @result;
  7237. }
  7238.  
  7239.  
  7240. # @VALUES
  7241. # variable_value_as_list ($VAR, $COND, $PARENT)
  7242. # ---------------------------------------------
  7243. # Get the value of a variable given a specified condition. without
  7244. # recursing through any subvariables.
  7245. # Arguments are:
  7246. #   $VAR    is the variable
  7247. #   $COND   is the condition.  If this is not given, the value for the
  7248. #           "TRUE" condition will be returned.
  7249. #   $PARENT is the variable in which the variable is used: this is used
  7250. #           only for error messages.
  7251. # Returns the list of conditions.
  7252. # For example, if A is defined as "foo $(B) bar", and B is defined as
  7253. # "baz", this will return ("foo", "$(B)", "bar")
  7254. sub variable_value_as_list
  7255. {
  7256.     my ($var, $cond, $parent) = @_;
  7257.     my @result;
  7258.  
  7259.     # Check defined
  7260.     return
  7261.       unless variable_assert $var, $parent;
  7262.  
  7263.     # Get value for given condition
  7264.     $cond ||= 'TRUE';
  7265.     my $onceflag;
  7266.     foreach my $vcond (keys %{$var_value{$var}})
  7267.     {
  7268.     my $val = $var_value{$var}{$vcond};
  7269.  
  7270.     if (&conditional_true_when ($vcond, $cond))
  7271.     {
  7272.         # Unless variable is not defined conditionally, there should only
  7273.         # be one value of $vcond true when $cond.
  7274.         &check_variable_defined_unconditionally ($var, $parent)
  7275.             if $onceflag;
  7276.         $onceflag = 1;
  7277.  
  7278.         # Strip backslashes
  7279.         $val =~ s/\\(\n|$)/ /g;
  7280.  
  7281.         foreach (split (' ', $val))
  7282.         {
  7283.         # If a comment seen, just leave.
  7284.         last if /^#/;
  7285.  
  7286.         push (@result, $_);
  7287.         }
  7288.     }
  7289.     }
  7290.  
  7291.     return @result;
  7292. }
  7293.  
  7294.  
  7295. # @VALUE
  7296. # &variable_value_as_list_recursive_worker ($VAR, $COND, $PARENT)
  7297. # ---------------------------------------------------------------
  7298. # Return contents of VAR as a list, split on whitespace.  This will
  7299. # recursively follow $(...) and ${...} inclusions.  It preserves @...@
  7300. # substitutions.  If COND is 'all', then all values under all
  7301. # conditions should be returned; if COND is a particular condition
  7302. # (all conditions are surrounded by @...@) then only the value for
  7303. # that condition should be returned; otherwise, warn if VAR is
  7304. # conditionally defined.  If PARENT is specified, it is the name of
  7305. # the including variable; this is only used for error reports.
  7306. sub variable_value_as_list_recursive_worker ($$$)
  7307. {
  7308.     my ($var, $cond, $parent) = @_;
  7309.     my @result = ();
  7310.  
  7311.     return
  7312.       unless variable_assert $var, $parent;
  7313.  
  7314.     if (defined $vars_scanned{$var})
  7315.     {
  7316.     # `vars_scanned' is a global we use to keep track of which
  7317.     # variables we've already examined.
  7318.     err_var $parent, "variable `$var' recursively defined";
  7319.     }
  7320.     elsif ($cond eq 'all')
  7321.     {
  7322.     $vars_scanned{$var} = 1;
  7323.     foreach my $vcond (keys %{$var_value{$var}})
  7324.     {
  7325.         my $val = $var_value{$var}{$vcond};
  7326.         push (@result, &value_to_list ($var, $val, $cond));
  7327.     }
  7328.     }
  7329.     else
  7330.     {
  7331.         $cond ||= 'TRUE';
  7332.     $vars_scanned{$var} = 1;
  7333.     my $onceflag;
  7334.     foreach my $vcond (keys %{$var_value{$var}})
  7335.     {
  7336.         my $val = $var_value{$var}{$vcond};
  7337.         if (&conditional_true_when ($vcond, $cond))
  7338.         {
  7339.         # Warn if we have an ambiguity.  It's hard to know how
  7340.         # to handle this case correctly.
  7341.         &check_variable_defined_unconditionally ($var, $parent)
  7342.             if $onceflag;
  7343.         $onceflag = 1;
  7344.         push (@result, &value_to_list ($var, $val, $cond));
  7345.         }
  7346.     }
  7347.     }
  7348.  
  7349.     # Unset our entry in vars_scanned.  We only care about recursive
  7350.     # definitions.
  7351.     delete $vars_scanned{$var};
  7352.  
  7353.     return @result;
  7354. }
  7355.  
  7356.  
  7357. # &variable_output ($VAR, [@CONDS])
  7358. # ---------------------------------
  7359. # Output all the values of $VAR if @COND is not specified, else only
  7360. # that corresponding to @COND.
  7361. sub variable_output ($@)
  7362. {
  7363.   my ($var, @conds) = @_;
  7364.  
  7365.   @conds = keys %{$var_value{$var}}
  7366.     unless @conds;
  7367.  
  7368.   foreach my $cond (sort by_condition @conds)
  7369.     {
  7370.       prog_error ("unknown condition `$cond' for `$var'")
  7371.     unless exists $var_value{$var}{$cond};
  7372.  
  7373.       if (exists $var_comment{$var} && exists $var_comment{$var}{$cond})
  7374.     {
  7375.       $output_vars .= $var_comment{$var}{$cond};
  7376.     }
  7377.  
  7378.       my $val = $var_value{$var}{$cond};
  7379.       my $equals = $var_type{$var}{$cond} eq ':' ? ':=' : '=';
  7380.       my $output_var = "$var $equals $val";
  7381.       $output_var =~ s/^/make_condition ($cond)/meg;
  7382.       $output_vars .= $output_var . "\n";
  7383.     }
  7384. }
  7385.  
  7386.  
  7387. # &variable_pretty_output ($VAR, [@CONDS])
  7388. # ----------------------------------------
  7389. # Likewise, but pretty, i.e., we *split* the values at spaces.   Use only
  7390. # with variables holding filenames.
  7391. sub variable_pretty_output ($@)
  7392. {
  7393.   my ($var, @conds) = @_;
  7394.  
  7395.   @conds = keys %{$var_value{$var}}
  7396.     unless @conds;
  7397.  
  7398.   foreach my $cond (sort by_condition @conds)
  7399.     {
  7400.       prog_error ("unknown condition `$cond' for `$var'")
  7401.     unless exists $var_value{$var}{$cond};
  7402.  
  7403.       if (exists $var_comment{$var} && exists $var_comment{$var}{$cond})
  7404.     {
  7405.       $output_vars .= $var_comment{$var}{$cond};
  7406.     }
  7407.  
  7408.       my $val = $var_value{$var}{$cond};
  7409.       my $equals = $var_type{$var}{$cond} eq ':' ? ':=' : '=';
  7410.       my $make_condition = make_condition ($cond);
  7411.  
  7412.       # Suppress escaped new lines.  &pretty_print_internal will
  7413.       # add them back, maybe at other places.
  7414.       $val =~ s/\\$//mg;
  7415.  
  7416.       $output_vars .= pretty_print_internal ("$make_condition$var $equals",
  7417.                          "$make_condition\t",
  7418.                          split (' ' , $val));
  7419.     }
  7420. }
  7421.  
  7422.  
  7423. # &variable_value_as_list_recursive ($VAR, $COND, $PARENT)
  7424. # --------------------------------------------------------
  7425. # This is just a wrapper for variable_value_as_list_recursive_worker that
  7426. # initializes the global hash `vars_scanned'.  This hash is used to
  7427. # avoid infinite recursion.
  7428. sub variable_value_as_list_recursive ($$@)
  7429. {
  7430.     my ($var, $cond, $parent) = @_;
  7431.     %vars_scanned = ();
  7432.     return &variable_value_as_list_recursive_worker ($var, $cond, $parent);
  7433. }
  7434.  
  7435.  
  7436. # &define_pretty_variable ($VAR, $COND, @VALUE)
  7437. # ---------------------------------------------
  7438. # Like define_variable, but the value is a list, and the variable may
  7439. # be defined conditionally.  The second argument is the conditional
  7440. # under which the value should be defined; this should be the empty
  7441. # string to define the variable unconditionally.  The third argument
  7442. # is a list holding the values to use for the variable.  The value is
  7443. # pretty printed in the output file.
  7444. sub define_pretty_variable ($$@)
  7445. {
  7446.     my ($var, $cond, @value) = @_;
  7447.  
  7448.     # Beware that an empty $cond has a different semantics for
  7449.     # macro_define and variable_pretty_output.
  7450.     $cond ||= 'TRUE';
  7451.  
  7452.     if (! variable_defined ($var, $cond))
  7453.     {
  7454.         macro_define ($var, VAR_AUTOMAKE, '', $cond, "@value", undef);
  7455.     variable_pretty_output ($var, $cond || 'TRUE');
  7456.     $content_seen{$var} = 1;
  7457.     }
  7458. }
  7459.  
  7460.  
  7461. # define_variable ($VAR, $VALUE)
  7462. # ------------------------------
  7463. # Define a new user variable VAR to VALUE, but only if not already defined.
  7464. sub define_variable ($$)
  7465. {
  7466.     my ($var, $value) = @_;
  7467.     define_pretty_variable ($var, 'TRUE', $value);
  7468. }
  7469.  
  7470.  
  7471. # Like define_variable, but define a variable to be the configure
  7472. # substitution by the same name.
  7473. sub define_configure_variable ($)
  7474. {
  7475.   my ($var) = @_;
  7476.   if (! variable_defined ($var, 'TRUE')
  7477.       # Explicitly avoid ANSI2KNR -- we AC_SUBST that in
  7478.       # protos.m4, but later define it elsewhere.  This is
  7479.       # pretty hacky.  We also explicitly avoid AMDEPBACKSLASH:
  7480.       # it might be subst'd by `\', which certainly would not be
  7481.       # appreciated by Make.
  7482.       && ! grep { $_ eq $var } (qw(ANSI2KNR AMDEPBACKSLASH)))
  7483.     {
  7484.       macro_define ($var, VAR_CONFIGURE, '', 'TRUE',
  7485.             subst $var, $configure_vars{$var});
  7486.       variable_pretty_output ($var, 'TRUE');
  7487.     }
  7488. }
  7489.  
  7490.  
  7491. # define_compiler_variable ($LANG)
  7492. # --------------------------------
  7493. # Define a compiler variable.  We also handle defining the `LT'
  7494. # version of the command when using libtool.
  7495. sub define_compiler_variable ($)
  7496. {
  7497.     my ($lang) = @_;
  7498.  
  7499.     my ($var, $value) = ($lang->compiler, $lang->compile);
  7500.     &define_variable ($var, $value);
  7501.     &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
  7502.       if variable_defined ('LIBTOOL');
  7503. }
  7504.  
  7505.  
  7506. # define_linker_variable ($LANG)
  7507. # ------------------------------
  7508. # Define linker variables.
  7509. sub define_linker_variable ($)
  7510. {
  7511.     my ($lang) = @_;
  7512.  
  7513.     my ($var, $value) = ($lang->lder, $lang->ld);
  7514.     # CCLD = $(CC).
  7515.     &define_variable ($lang->lder, $lang->ld);
  7516.     # CCLINK = $(CCLD) blah blah...
  7517.     &define_variable ($lang->linker,
  7518.               ((variable_defined ('LIBTOOL')
  7519.             ? '$(LIBTOOL) --mode=link ' : '')
  7520.                . $lang->link));
  7521. }
  7522.  
  7523. ################################################################
  7524.  
  7525. ## ---------------- ##
  7526. ## Handling rules.  ##
  7527. ## ---------------- ##
  7528.  
  7529. sub register_suffix_rule ($$$)
  7530. {
  7531.   my ($where, $src, $dest) = @_;
  7532.  
  7533.   verb "Sources ending in $src become $dest";
  7534.   push @suffixes, $src, $dest;
  7535.  
  7536.   # When transforming sources to objects, Automake uses the
  7537.   # %suffix_rules to move from each source extension to
  7538.   # `.$(OBJEXT)', not to `.o' or `.obj'.  However some people
  7539.   # define suffix rules for `.o' or `.obj', so internally we will
  7540.   # consider these extensions equivalent to `.$(OBJEXT)'.  We
  7541.   # CANNOT rewrite the target (i.e., automagically replace `.o'
  7542.   # and `.obj' by `.$(OBJEXT)' in the output), or warn the user
  7543.   # that (s)he'd better use `.$(OBJEXT)', because Automake itself
  7544.   # output suffix rules for `.o' or `.obj'...
  7545.   $dest = '.$(OBJEXT)' if ($dest eq '.o' || $dest eq '.obj');
  7546.  
  7547.   # Reading the comments near the declaration of $suffix_rules might
  7548.   # help to understand the update of $suffix_rules that follows...
  7549.  
  7550.   # Register $dest as a possible destination from $src.
  7551.   # We might have the create the \hash.
  7552.   if (exists $suffix_rules->{$src})
  7553.     {
  7554.       $suffix_rules->{$src}{$dest} = [ $dest, 1 ];
  7555.     }
  7556.   else
  7557.     {
  7558.       $suffix_rules->{$src} = { $dest => [ $dest, 1 ] };
  7559.     }
  7560.  
  7561.   # If we know how to transform $dest in something else, then
  7562.   # we know how to transform $src in that "something else".
  7563.   if (exists $suffix_rules->{$dest})
  7564.     {
  7565.       for my $dest2 (keys %{$suffix_rules->{$dest}})
  7566.     {
  7567.       my $dist = $suffix_rules->{$dest}{$dest2}[1] + 1;
  7568.       # Overwrite an existing $src->$dest2 path only if
  7569.       # the path via $dest which is shorter.
  7570.       if (! exists $suffix_rules->{$src}{$dest2}
  7571.           || $suffix_rules->{$src}{$dest2}[1] > $dist)
  7572.         {
  7573.           $suffix_rules->{$src}{$dest2} = [ $dest, $dist ];
  7574.         }
  7575.     }
  7576.     }
  7577.  
  7578.   # Similarly, any extension that can be derived into $src
  7579.   # can be derived into the same extensions as $src can.
  7580.   my @dest2 = keys %{$suffix_rules->{$src}};
  7581.   for my $src2 (keys %$suffix_rules)
  7582.     {
  7583.       if (exists $suffix_rules->{$src2}{$src})
  7584.     {
  7585.       for my $dest2 (@dest2)
  7586.         {
  7587.           my $dist = $suffix_rules->{$src}{$dest2} + 1;
  7588.           # Overwrite an existing $src2->$dest2 path only if
  7589.           # the path via $src is shorter.
  7590.           if (! exists $suffix_rules->{$src2}{$dest2}
  7591.           || $suffix_rules->{$src2}{$dest2}[1] > $dist)
  7592.         {
  7593.           $suffix_rules->{$src2}{$dest2} = [ $src, $dist ];
  7594.         }
  7595.         }
  7596.     }
  7597.     }
  7598. }
  7599.  
  7600. # @CONDS
  7601. # rule_define ($TARGET, $SOURCE, $OWNER, $COND, $WHERE)
  7602. # -----------------------------------------------------
  7603. # Define a new rule.  $TARGET is the rule name.  $SOURCE
  7604. # is the filename the rule comes from.  $OWNER is the
  7605. # owner of the rule (TARGET_AUTOMAKE or TARGET_USER).
  7606. # $COND is the condition string under which the rule is defined.
  7607. # $WHERE is where the rule is defined (file name and/or line number).
  7608. # Returns a (possibly empty) list of conditions where the rule
  7609. # should be defined.
  7610. sub rule_define ($$$$$)
  7611. {
  7612.   my ($target, $source, $owner, $cond, $where) = @_;
  7613.  
  7614.   # Don't even think about defining a rule in condition FALSE.
  7615.   return () if $cond eq 'FALSE';
  7616.  
  7617.   # For now `foo:' will override `foo$(EXEEXT):'.  This is temporary,
  7618.   # though, so we emit a warning.
  7619.   (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
  7620.   if ($noexe ne $target
  7621.       && exists $targets{$noexe}
  7622.       && exists $targets{$noexe}{$cond}
  7623.       && $target_name{$noexe}{$cond} ne $target)
  7624.     {
  7625.       # The no-exeext option enables this feature.
  7626.       if (! defined $options{'no-exeext'})
  7627.     {
  7628.       msg ('obsolete', $noexe,
  7629.            "deprecated feature: `$noexe' overrides `$noexe\$(EXEEXT)'\n"
  7630.            . "change your target to read `$noexe\$(EXEEXT)'");
  7631.     }
  7632.       # Don't define.
  7633.       return ();
  7634.     }
  7635.  
  7636.   # For now on, strip off $(EXEEXT) from $target, so we can diagnose
  7637.   # a clash if `ctags$(EXEEXT):' is redefined after `ctags:'.
  7638.   my $realtarget = $target;
  7639.   $target = $noexe;
  7640.  
  7641.   # A GNU make-style pattern rule has a single "%" in the target name.
  7642.   msg ('portability', $where,
  7643.        "`%'-style pattern rules are a GNU make extension")
  7644.     if $target =~ /^[^%]*%[^%]*$/;
  7645.  
  7646.   # Diagnose target redefinitions.
  7647.   if (exists $target_source{$target}{$cond})
  7648.     {
  7649.       # Sanity checks.
  7650.       prog_error ("\$target_source{$target}{$cond} exists, but \$target_owner"
  7651.           . " doesn't.")
  7652.     unless exists $target_owner{$target}{$cond};
  7653.       prog_error ("\$target_source{$target}{$cond} exists, but \$targets"
  7654.           . " doesn't.")
  7655.     unless exists $targets{$target}{$cond};
  7656.       prog_error ("\$target_source{$target}{$cond} exists, but \$target_name"
  7657.           . " doesn't.")
  7658.     unless exists $target_name{$target}{$cond};
  7659.  
  7660.       my $oldowner  = $target_owner{$target}{$cond};
  7661.  
  7662.       # Don't mention true conditions in diagnostics.
  7663.       my $condmsg = $cond ne 'TRUE' ? " in condition `$cond'" : '';
  7664.  
  7665.       if ($owner == TARGET_USER)
  7666.     {
  7667.       if ($oldowner eq TARGET_USER)
  7668.         {
  7669.           # Ignore `%'-style pattern rules.  We'd need the
  7670.           # dependencies to detect duplicates, and they are
  7671.           # already diagnosed as unportable by -Wportability.
  7672.           if ($target !~ /^[^%]*%[^%]*$/)
  7673.         {
  7674.           ## FIXME: Presently we can't diagnose duplicate user rules
  7675.           ## because we doesn't distinguish rules with commands
  7676.           ## from rules that only add dependencies.  E.g.,
  7677.           ##   .PHONY: foo
  7678.           ##   .PHONY: bar
  7679.           ## is legitimate. (This is phony.test.)
  7680.  
  7681.           # msg ('syntax', $where,
  7682.           #      "redefinition of `$target'$condmsg...");
  7683.           # msg_cond_target ('syntax', $cond, $target,
  7684.           #            "... `$target' previously defined here.");
  7685.         }
  7686.           # Return so we don't redefine the rule in our tables,
  7687.           # don't check for ambiguous conditional, etc.  The rule
  7688.           # will be output anyway beauce &read_am_file ignore the
  7689.           # return code.
  7690.           return ();
  7691.         }
  7692.       else
  7693.         {
  7694.           # Since we parse the user Makefile.am before reading
  7695.           # the Automake fragments, this condition should never happen.
  7696.           prog_error ("user target `$target' seen after Automake's "
  7697.               . "definition\nfrom `$targets{$target}$condmsg'");
  7698.         }
  7699.     }
  7700.       else # $owner == TARGET_AUTOMAKE
  7701.     {
  7702.       if ($oldowner == TARGET_USER)
  7703.         {
  7704.           # Don't overwrite the user definition of TARGET.
  7705.           return ();
  7706.         }
  7707.       else # $oldowner == TARGET_AUTOMAKE
  7708.         {
  7709.           # Automake should ignore redefinitions of its own
  7710.           # rules if they came from the same file.  This makes
  7711.           # it easier to process a Makefile fragment several times.
  7712.           # Hower it's an error if the target is defined in many
  7713.           # files.  E.g., the user might be using bin_PROGRAMS = ctags
  7714.           # which clashes with our `ctags' rule.
  7715.           # (It would be more accurate if we had a way to compare
  7716.           # the *content* of both rules.  Then $targets_source would
  7717.           # be useless.)
  7718.           my $oldsource = $target_source{$target}{$cond};
  7719.           return () if $source eq $oldsource;
  7720.  
  7721.           msg ('syntax', $where, "redefinition of `$target'$condmsg...");
  7722.           msg_cond_target ('syntax', $cond, $target,
  7723.                    "... `$target' previously defined here.");
  7724.           return ();
  7725.         }
  7726.     }
  7727.       # Never reached.
  7728.       prog_error ("Unreachable place reached.");
  7729.     }
  7730.  
  7731.   # Conditions for which the rule should be defined.
  7732.   my @conds = $cond;
  7733.  
  7734.   # Check ambiguous conditional definitions.
  7735.   my ($message, $ambig_cond) =
  7736.     conditional_ambiguous_p ($target, $cond, keys %{$targets{$target}});
  7737.   if ($message)            # We have an ambiguity.
  7738.     {
  7739.       if ($owner == TARGET_USER)
  7740.     {
  7741.       # For user rules, just diagnose the ambiguity.
  7742.       msg 'syntax', $where, "$message ...";
  7743.       msg_cond_target ('syntax', $ambig_cond, $target,
  7744.                "... `$target' previously defined here.");
  7745.       return ();
  7746.     }
  7747.       else
  7748.     {
  7749.       # FIXME: for Automake rules, we can't diagnose ambiguities yet.
  7750.       # The point is that Automake doesn't propagate conditionals
  7751.       # everywhere.  For instance &handle_PROGRAMS doesn't care if
  7752.       # bin_PROGRAMS was defined conditionally or not.
  7753.       # On the following input
  7754.       #   if COND1
  7755.       #   foo:
  7756.       #           ...
  7757.       #   else
  7758.       #   bin_PROGRAMS = foo
  7759.       #   endif
  7760.       # &handle_PROGRAMS will attempt to define a `foo:' rule
  7761.       # in condition TRUE (which conflicts with COND1).  Fixing
  7762.       # this in &handle_PROGRAMS and siblings seems hard: you'd
  7763.       # have to explain &file_contents what to do with a
  7764.       # conditional.  So for now we do our best *here*.  If `foo:'
  7765.       # was already defined in condition COND1 and we want to define
  7766.       # it in condition TRUE, then define it only in condition !COND1.
  7767.       # (See cond14.test and cond15.test for some test cases.)
  7768.       my @defined_conds = keys %{$targets{$target}};
  7769.       @conds = ();
  7770.       for my $undefined_cond (invert_conditions(@defined_conds))
  7771.         {
  7772.           push @conds, make_condition ($cond, $undefined_cond);
  7773.         }
  7774.       # No conditions left to define the rule.
  7775.       # Warn, because our workaround is meaningless in this case.
  7776.       if (scalar @conds == 0)
  7777.         {
  7778.           msg 'syntax', $where, "$message ...";
  7779.           msg_cond_target ('syntax', $ambig_cond, $target,
  7780.                    "... `$target' previously defined here.");
  7781.           return ();
  7782.         }
  7783.     }
  7784.     }
  7785.  
  7786.   # Finally define this rule.
  7787.   for my $c (@conds)
  7788.     {
  7789.       $targets{$target}{$c} = $where;
  7790.       $target_source{$target}{$c} = $source;
  7791.       $target_owner{$target}{$c} = $owner;
  7792.       $target_name{$target}{$c} = $realtarget;
  7793.     }
  7794.  
  7795.   # We honor inference rules with multiple targets because many
  7796.   # make support this and people use it.  However this is disallowed
  7797.   # by POSIX.  We'll print a warning later.
  7798.   my $target_count = 0;
  7799.   my $inference_rule_count = 0;
  7800.   for my $t (split (' ', $target))
  7801.     {
  7802.       ++$target_count;
  7803.       # Check the rule for being a suffix rule. If so, store in a hash.
  7804.       # Either it's a rule for two known extensions...
  7805.       if ($t =~ /^($KNOWN_EXTENSIONS_PATTERN)($KNOWN_EXTENSIONS_PATTERN)$/
  7806.       # ...or it's a rule with unknown extensions (.i.e, the rule
  7807.       # looks like `.foo.bar:' but `.foo' or `.bar' are not
  7808.       # declared in SUFFIXES and are not known language
  7809.       # extensions).  Automake will complete SUFFIXES from
  7810.       # @suffixes automatically (see handle_footer).
  7811.       || ($t =~ /$SUFFIX_RULE_PATTERN/o && accept_extensions($1)))
  7812.     {
  7813.       ++$inference_rule_count;
  7814.       register_suffix_rule ($where, $1, $2);
  7815.     }
  7816.     }
  7817.  
  7818.   # POSIX allows multiple targets before the colon, but disallows
  7819.   # definitions of multiple inference rules.  It's also
  7820.   # disallowed to mix plain targets with inference rules.
  7821.   msg ('portability', $where,
  7822.        "Inference rules can have only one target before the colon (POSIX).")
  7823.     if $inference_rule_count > 0 && $target_count > 1;
  7824.  
  7825.   # Return "" instead of TRUE so it can be used with make_paragraphs
  7826.   # directly.
  7827.   return "" if 1 == @conds && $conds[0] eq 'TRUE';
  7828.   return @conds;
  7829. }
  7830.  
  7831.  
  7832. # See if a target exists.
  7833. sub target_defined
  7834. {
  7835.     my ($target) = @_;
  7836.     return exists $targets{$target};
  7837. }
  7838.  
  7839.  
  7840. ################################################################
  7841.  
  7842. # &check_trailing_slash ($WHERE, $LINE)
  7843. # --------------------------------------
  7844. # Return 1 iff $LINE ends with a slash.
  7845. # Might modify $LINE.
  7846. sub check_trailing_slash ($\$)
  7847. {
  7848.   my ($where, $line) = @_;
  7849.  
  7850.   # Ignore `##' lines.
  7851.   return 0 if $$line =~ /$IGNORE_PATTERN/o;
  7852.  
  7853.   # Catch and fix a common error.
  7854.   msg "syntax", $where, "whitespace following trailing backslash"
  7855.     if $$line =~ s/\\\s+\n$/\\\n/;
  7856.  
  7857.   return $$line =~ /\\$/;
  7858. }
  7859.  
  7860.  
  7861. # &append_comments ($VARIABLE, $SPACING, $COMMENT)
  7862. # ------------------------------------------------
  7863. # Append $COMMENT to the other comments for $VARIABLE, using
  7864. # $SPACING as separator.
  7865. sub append_comments ($$$$)
  7866. {
  7867.     my ($cond, $var, $spacing, $comment) = @_;
  7868.     $var_comment{$var}{$cond} .= $spacing
  7869.     if (!defined $var_comment{$var}{$cond}
  7870.         || $var_comment{$var}{$cond} !~ /\n$/o);
  7871.     $var_comment{$var}{$cond} .= $comment;
  7872. }
  7873.  
  7874.  
  7875. # &read_am_file ($AMFILE)
  7876. # -----------------------
  7877. # Read Makefile.am and set up %contents.  Simultaneously copy lines
  7878. # from Makefile.am into $output_trailer or $output_vars as
  7879. # appropriate.  NOTE we put rules in the trailer section.  We want
  7880. # user rules to come after our generated stuff.
  7881. sub read_am_file ($)
  7882. {
  7883.     my ($amfile) = @_;
  7884.  
  7885.     my $am_file = new Automake::XFile ("< $amfile");
  7886.     verb "reading $amfile";
  7887.  
  7888.     my $spacing = '';
  7889.     my $comment = '';
  7890.     my $blank = 0;
  7891.     my $saw_bk = 0;
  7892.  
  7893.     use constant IN_VAR_DEF => 0;
  7894.     use constant IN_RULE_DEF => 1;
  7895.     use constant IN_COMMENT => 2;
  7896.     my $prev_state = IN_RULE_DEF;
  7897.  
  7898.     while ($_ = $am_file->getline)
  7899.     {
  7900.     if (/$IGNORE_PATTERN/o)
  7901.     {
  7902.         # Merely delete comments beginning with two hashes.
  7903.     }
  7904.     elsif (/$WHITE_PATTERN/o)
  7905.     {
  7906.         error "$amfile:$.", "blank line following trailing backslash"
  7907.           if $saw_bk;
  7908.         # Stick a single white line before the incoming macro or rule.
  7909.         $spacing = "\n";
  7910.         $blank = 1;
  7911.         # Flush all comments seen so far.
  7912.         if ($comment ne '')
  7913.         {
  7914.         $output_vars .= $comment;
  7915.         $comment = '';
  7916.         }
  7917.     }
  7918.     elsif (/$COMMENT_PATTERN/o)
  7919.     {
  7920.         # Stick comments before the incoming macro or rule.  Make
  7921.         # sure a blank line precedes the first block of comments.
  7922.         $spacing = "\n" unless $blank;
  7923.         $blank = 1;
  7924.         $comment .= $spacing . $_;
  7925.         $spacing = '';
  7926.         $prev_state = IN_COMMENT;
  7927.     }
  7928.     else
  7929.     {
  7930.         last;
  7931.     }
  7932.     $saw_bk = check_trailing_slash ("$amfile:$.", $_);
  7933.     }
  7934.  
  7935.     # We save the conditional stack on entry, and then check to make
  7936.     # sure it is the same on exit.  This lets us conditionally include
  7937.     # other files.
  7938.     my @saved_cond_stack = @cond_stack;
  7939.     my $cond = conditional_string (@cond_stack);
  7940.  
  7941.     my $last_var_name = '';
  7942.     my $last_var_type = '';
  7943.     my $last_var_value = '';
  7944.     # FIXME: shouldn't use $_ in this loop; it is too big.
  7945.     while ($_)
  7946.     {
  7947.         my $here = "$amfile:$.";
  7948.  
  7949.     # Make sure the line is \n-terminated.
  7950.     chomp;
  7951.     $_ .= "\n";
  7952.  
  7953.     # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
  7954.     # used by users.  @MAINT@ is an anachronism now.
  7955.     $_ =~ s/\@MAINT\@//g
  7956.         unless $seen_maint_mode;
  7957.  
  7958.     my $new_saw_bk = check_trailing_slash ($here, $_);
  7959.  
  7960.     if (/$IGNORE_PATTERN/o)
  7961.     {
  7962.         # Merely delete comments beginning with two hashes.
  7963.     }
  7964.     elsif (/$WHITE_PATTERN/o)
  7965.     {
  7966.         # Stick a single white line before the incoming macro or rule.
  7967.         $spacing = "\n";
  7968.         error $here, "blank line following trailing backslash"
  7969.           if $saw_bk;
  7970.     }
  7971.     elsif (/$COMMENT_PATTERN/o)
  7972.     {
  7973.         # Stick comments before the incoming macro or rule.
  7974.         $comment .= $spacing . $_;
  7975.         $spacing = '';
  7976.         error $here, "comment following trailing backslash"
  7977.           if $saw_bk && $comment eq '';
  7978.         $prev_state = IN_COMMENT;
  7979.     }
  7980.     elsif ($saw_bk)
  7981.     {
  7982.         if ($prev_state == IN_RULE_DEF)
  7983.         {
  7984.             $output_trailer .= &make_condition (@cond_stack);
  7985.         $output_trailer .= $_;
  7986.         }
  7987.         elsif ($prev_state == IN_COMMENT)
  7988.         {
  7989.         # If the line doesn't start with a `#', add it.
  7990.         # We do this because a continued comment like
  7991.         #   # A = foo \
  7992.         #         bar \
  7993.         #         baz
  7994.         # is not portable.  BSD make doesn't honor
  7995.         # escaped newlines in comments.
  7996.         s/^#?/#/;
  7997.         $comment .= $spacing . $_;
  7998.         }
  7999.         else # $prev_state == IN_VAR_DEF
  8000.         {
  8001.           $last_var_value .= ' '
  8002.         unless $last_var_value =~ /\s$/;
  8003.           $last_var_value .= $_;
  8004.  
  8005.           if (!/\\$/)
  8006.         {
  8007.           append_comments ($cond || 'TRUE',
  8008.                    $last_var_name, $spacing, $comment);
  8009.           $comment = $spacing = '';
  8010.           macro_define ($last_var_name, VAR_MAKEFILE,
  8011.                 $last_var_type, $cond,
  8012.                 $last_var_value, $here)
  8013.             if $cond ne 'FALSE';
  8014.           push (@var_list, $last_var_name);
  8015.         }
  8016.         }
  8017.     }
  8018.  
  8019.     elsif (/$IF_PATTERN/o)
  8020.       {
  8021.         $cond = cond_stack_if ($1, $2, $here);
  8022.       }
  8023.     elsif (/$ELSE_PATTERN/o)
  8024.       {
  8025.         $cond = cond_stack_else ($1, $2, $here);
  8026.       }
  8027.     elsif (/$ENDIF_PATTERN/o)
  8028.       {
  8029.         $cond = cond_stack_endif ($1, $2, $here);
  8030.       }
  8031.  
  8032.     elsif (/$RULE_PATTERN/o)
  8033.     {
  8034.         # Found a rule.
  8035.         $prev_state = IN_RULE_DEF;
  8036.  
  8037.         # For now we have to output all definitions of user rules
  8038.         # and can't diagnose duplicates (see the comment in
  8039.         # rule_define). So we go on and ignore the return value.
  8040.         rule_define ($1, $amfile, TARGET_USER, $cond || 'TRUE', $here);
  8041.  
  8042.         check_variable_expansions ($_, $here);
  8043.  
  8044.         $output_trailer .= $comment . $spacing;
  8045.             $output_trailer .= &make_condition (@cond_stack);
  8046.             $output_trailer .= $_;
  8047.         $comment = $spacing = '';
  8048.     }
  8049.     elsif (/$ASSIGNMENT_PATTERN/o)
  8050.     {
  8051.         # Found a macro definition.
  8052.         $prev_state = IN_VAR_DEF;
  8053.         $last_var_name = $1;
  8054.         $last_var_type = $2;
  8055.         $last_var_value = $3;
  8056.         if ($3 ne '' && substr ($3, -1) eq "\\")
  8057.         {
  8058.         # We preserve the `\' because otherwise the long lines
  8059.         # that are generated will be truncated by broken
  8060.         # `sed's.
  8061.         $last_var_value = $3 . "\n";
  8062.         }
  8063.  
  8064.         if (!/\\$/)
  8065.           {
  8066.         # Accumulating variables must not be output.
  8067.         append_comments ($cond || 'TRUE',
  8068.                  $last_var_name, $spacing, $comment);
  8069.         $comment = $spacing = '';
  8070.  
  8071.         macro_define ($last_var_name, VAR_MAKEFILE,
  8072.                   $last_var_type, $cond,
  8073.                   $last_var_value, $here)
  8074.           if $cond ne 'FALSE';
  8075.         push (@var_list, $last_var_name);
  8076.           }
  8077.     }
  8078.         elsif (/$INCLUDE_PATTERN/o)
  8079.         {
  8080.             my $path = $1;
  8081.  
  8082.             if ($path =~ s/^\$\(top_srcdir\)\///)
  8083.           {
  8084.                 push (@include_stack, "\$\(top_srcdir\)/$path");
  8085.         # Distribute any included file.
  8086.  
  8087.         # Always use the $(top_srcdir) prefix in DIST_COMMON,
  8088.         # otherwise OSF make will implicitly copy the included
  8089.         # file in the build tree during `make distdir' to satisfy
  8090.         # the dependency.
  8091.         # (subdircond2.test and subdircond3.test will fail.)
  8092.         push_dist_common ("\$\(top_srcdir\)/$path");
  8093.           }
  8094.             else
  8095.           {
  8096.                 $path =~ s/\$\(srcdir\)\///;
  8097.                 push (@include_stack, "\$\(srcdir\)/$path");
  8098.         # Always use the $(srcdir) prefix in DIST_COMMON,
  8099.         # otherwise OSF make will implicitly copy the included
  8100.         # file in the build tree during `make distdir' to satisfy
  8101.         # the dependency.
  8102.         # (subdircond2.test and subdircond3.test will fail.)
  8103.         push_dist_common ("\$\(srcdir\)/$path");
  8104.         $path = $relative_dir . "/" . $path;
  8105.           }
  8106.             &read_am_file ($path);
  8107.         }
  8108.     else
  8109.         {
  8110.         # This isn't an error; it is probably a continued rule.
  8111.         # In fact, this is what we assume.
  8112.         $prev_state = IN_RULE_DEF;
  8113.         check_variable_expansions ($_, $here);
  8114.         $output_trailer .= $comment . $spacing;
  8115.         $output_trailer .= &make_condition  (@cond_stack);
  8116.         $output_trailer .= $_;
  8117.         $comment = $spacing = '';
  8118.         error $here, "`#' comment at start of rule is unportable"
  8119.           if $_ =~ /^\t\s*\#/;
  8120.     }
  8121.  
  8122.     $saw_bk = $new_saw_bk;
  8123.         $_ = $am_file->getline;
  8124.     }
  8125.  
  8126.     $output_trailer .= $comment;
  8127.  
  8128.     err_am ("trailing backslash on last line")
  8129.       if $saw_bk;
  8130.  
  8131.     err_am (@cond_stack ? "unterminated conditionals: @cond_stack"
  8132.         : "too many conditionals closed in include file")
  8133.       if "@saved_cond_stack" ne "@cond_stack";
  8134. }
  8135.  
  8136.  
  8137. # define_standard_variables ()
  8138. # ----------------------------
  8139. # A helper for read_main_am_file which initializes configure variables
  8140. # and variables from header-vars.am.
  8141. sub define_standard_variables
  8142. {
  8143.     my $saved_output_vars = $output_vars;
  8144.     my ($comments, undef, $rules) =
  8145.       file_contents_internal (1, "$libdir/am/header-vars.am");
  8146.  
  8147.     # This will output the definitions in $output_vars, which we don't
  8148.     # want...
  8149.     foreach my $var (sort keys %configure_vars)
  8150.     {
  8151.         &define_configure_variable ($var);
  8152.         push (@var_list, $var);
  8153.     }
  8154.  
  8155.     # ... hence, we restore $output_vars.
  8156.     $output_vars = $saved_output_vars . $comments . $rules;
  8157. }
  8158.  
  8159. # Read main am file.
  8160. sub read_main_am_file
  8161. {
  8162.     my ($amfile) = @_;
  8163.  
  8164.     # This supports the strange variable tricks we are about to play.
  8165.     prog_error (macros_dump () . "variable defined before read_main_am_file")
  8166.       if (scalar keys %var_value > 0);
  8167.  
  8168.     # Generate copyright header for generated Makefile.in.
  8169.     # We do discard the output of predefined variables, handled below.
  8170.     $output_vars = ("# $in_file_name generated by automake "
  8171.            . $VERSION . " from $am_file_name.\n");
  8172.     $output_vars .= '# ' . subst ('configure_input') . "\n";
  8173.     $output_vars .= $gen_copyright;
  8174.  
  8175.     # We want to predefine as many variables as possible.  This lets
  8176.     # the user set them with `+=' in Makefile.am.  However, we don't
  8177.     # want these initial definitions to end up in the output quite
  8178.     # yet.  So we just load them, but output them later.
  8179.     &define_standard_variables;
  8180.  
  8181.     # Read user file, which might override some of our values.
  8182.     &read_am_file ($amfile);
  8183.  
  8184.     # Output all the Automake variables.  If the user changed one,
  8185.     # then it is now marked as VAR_CONFIGURE or VAR_MAKEFILE.
  8186.     foreach my $var (uniq @var_list)
  8187.     {
  8188.       # Some variables, like AMDEPBACKSLASH are in @var_list
  8189.       # but don't have a owner.  This is good, because we don't want
  8190.       # to output them.
  8191.       foreach my $cond (keys %{$var_owner{$var}})
  8192.     {
  8193.       variable_output ($var, $cond)
  8194.         if $var_owner{$var}{$cond} == VAR_AUTOMAKE;
  8195.     }
  8196.     }
  8197.  
  8198.     # Now dump the user variables that were defined.  We do it in the same
  8199.     # order in which they were defined (skipping duplicates).
  8200.     foreach my $var (uniq @var_list)
  8201.     {
  8202.       foreach my $cond (keys %{$var_owner{$var}})
  8203.     {
  8204.       variable_output ($var, $cond)
  8205.         if $var_owner{$var}{$cond} != VAR_AUTOMAKE;
  8206.     }
  8207.     }
  8208. }
  8209.  
  8210. ################################################################
  8211.  
  8212. # $FLATTENED
  8213. # &flatten ($STRING)
  8214. # ------------------
  8215. # Flatten the $STRING and return the result.
  8216. sub flatten
  8217. {
  8218.   $_ = shift;
  8219.  
  8220.   s/\\\n//somg;
  8221.   s/\s+/ /g;
  8222.   s/^ //;
  8223.   s/ $//;
  8224.  
  8225.   return $_;
  8226. }
  8227.  
  8228.  
  8229. # @PARAGRAPHS
  8230. # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
  8231. # ------------------------------------------
  8232. # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
  8233. # paragraphs.
  8234. sub make_paragraphs ($%)
  8235. {
  8236.     my ($file, %transform) = @_;
  8237.  
  8238.     # Complete %transform with global options and make it a Perl
  8239.     # $command.
  8240.     my $command =
  8241.       "s/$IGNORE_PATTERN//gm;"
  8242.     . transform (%transform,
  8243.  
  8244.              'CYGNUS'          => $cygnus_mode,
  8245.              'MAINTAINER-MODE'
  8246.              => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
  8247.  
  8248.              'SHAR'        => $options{'dist-shar'} || 0,
  8249.              'BZIP2'       => $options{'dist-bzip2'} || 0,
  8250.              'ZIP'         => $options{'dist-zip'} || 0,
  8251.              'COMPRESS'    => $options{'dist-tarZ'} || 0,
  8252.  
  8253.              'INSTALL-INFO' => !$options{'no-installinfo'},
  8254.              'INSTALL-MAN'  => !$options{'no-installman'},
  8255.              'CK-NEWS'      => $options{'check-news'} || 0,
  8256.  
  8257.              'SUBDIRS'      => variable_defined ('SUBDIRS'),
  8258.              'TOPDIR'       => backname ($relative_dir),
  8259.              'TOPDIR_P'     => $relative_dir eq '.',
  8260.              'CONFIGURE-AC' => $configure_ac,
  8261.  
  8262.              'BUILD'    => $seen_canonical == AC_CANONICAL_SYSTEM,
  8263.              'HOST'     => $seen_canonical,
  8264.              'TARGET'   => $seen_canonical == AC_CANONICAL_SYSTEM,
  8265.  
  8266.              'LIBTOOL'      => variable_defined ('LIBTOOL'))
  8267.       # We don't need more than two consecutive new-lines.
  8268.       . 's/\n{3,}/\n\n/g';
  8269.  
  8270.     # Swallow the file and apply the COMMAND.
  8271.     my $fc_file = new Automake::XFile "< $file";
  8272.     # Looks stupid?
  8273.     verb "reading $file";
  8274.     my $saved_dollar_slash = $/;
  8275.     undef $/;
  8276.     $_ = $fc_file->getline;
  8277.     $/ = $saved_dollar_slash;
  8278.     eval $command;
  8279.     $fc_file->close;
  8280.     my $content = $_;
  8281.  
  8282.     # Split at unescaped new lines.
  8283.     my @lines = split (/(?<!\\)\n/, $content);
  8284.     my @res;
  8285.  
  8286.     while (defined ($_ = shift @lines))
  8287.       {
  8288.     my $paragraph = "$_";
  8289.     # If we are a rule, eat as long as we start with a tab.
  8290.     if (/$RULE_PATTERN/smo)
  8291.       {
  8292.         while (defined ($_ = shift @lines) && $_ =~ /^\t/)
  8293.           {
  8294.         $paragraph .= "\n$_";
  8295.           }
  8296.         unshift (@lines, $_);
  8297.       }
  8298.  
  8299.     # If we are a comments, eat as much comments as you can.
  8300.     elsif (/$COMMENT_PATTERN/smo)
  8301.       {
  8302.         while (defined ($_ = shift @lines)
  8303.            && $_ =~ /$COMMENT_PATTERN/smo)
  8304.           {
  8305.         $paragraph .= "\n$_";
  8306.           }
  8307.         unshift (@lines, $_);
  8308.       }
  8309.  
  8310.     push @res, $paragraph;
  8311.     $paragraph = '';
  8312.       }
  8313.  
  8314.     return @res;
  8315. }
  8316.  
  8317.  
  8318.  
  8319. # ($COMMENT, $VARIABLES, $RULES)
  8320. # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
  8321. # -----------------------------------------------------
  8322. # Return contents of a file from $libdir/am, automatically skipping
  8323. # macros or rules which are already known. $IS_AM iff the caller is
  8324. # reading an Automake file (as opposed to the user's Makefile.am).
  8325. sub file_contents_internal ($$%)
  8326. {
  8327.     my ($is_am, $file, %transform) = @_;
  8328.  
  8329.     my $result_vars = '';
  8330.     my $result_rules = '';
  8331.     my $comment = '';
  8332.     my $spacing = '';
  8333.  
  8334.     # The following flags are used to track rules spanning across
  8335.     # multiple paragraphs.
  8336.     my $is_rule = 0;        # 1 if we are processing a rule.
  8337.     my $discard_rule = 0;    # 1 if the current rule should not be output.
  8338.  
  8339.     # We save the conditional stack on entry, and then check to make
  8340.     # sure it is the same on exit.  This lets us conditionally include
  8341.     # other files.
  8342.     my @saved_cond_stack = @cond_stack;
  8343.     my $cond = conditional_string (@cond_stack);
  8344.  
  8345.     foreach (make_paragraphs ($file, %transform))
  8346.     {
  8347.         # Sanity checks.
  8348.     error $file, "blank line following trailing backslash:\n$_"
  8349.       if /\\$/;
  8350.     error $file, "comment following trailing backslash:\n$_"
  8351.       if /\\#/;
  8352.  
  8353.      if (/^$/)
  8354.      {
  8355.         $is_rule = 0;
  8356.          # Stick empty line before the incoming macro or rule.
  8357.          $spacing = "\n";
  8358.      }
  8359.      elsif (/$COMMENT_PATTERN/mso)
  8360.      {
  8361.         $is_rule = 0;
  8362.          # Stick comments before the incoming macro or rule.
  8363.          $comment = "$_\n";
  8364.     }
  8365.  
  8366.     # Handle inclusion of other files.
  8367.         elsif (/$INCLUDE_PATTERN/o)
  8368.         {
  8369.         if ($cond ne 'FALSE')
  8370.           {
  8371.         my $file = ($is_am ? "$libdir/am/" : '') . $1;
  8372.         # N-ary `.=' fails.
  8373.         my ($com, $vars, $rules)
  8374.           = file_contents_internal ($is_am, $file, %transform);
  8375.         $comment .= $com;
  8376.         $result_vars .= $vars;
  8377.         $result_rules .= $rules;
  8378.           }
  8379.         }
  8380.  
  8381.         # Handling the conditionals.
  8382.         elsif (/$IF_PATTERN/o)
  8383.       {
  8384.         $cond = cond_stack_if ($1, $2, $file);
  8385.       }
  8386.     elsif (/$ELSE_PATTERN/o)
  8387.       {
  8388.         $cond = cond_stack_else ($1, $2, $file);
  8389.       }
  8390.     elsif (/$ENDIF_PATTERN/o)
  8391.       {
  8392.         $cond = cond_stack_endif ($1, $2, $file);
  8393.       }
  8394.  
  8395.         # Handling rules.
  8396.      elsif (/$RULE_PATTERN/mso)
  8397.      {
  8398.       $is_rule = 1;
  8399.       $discard_rule = 0;
  8400.       # Separate relationship from optional actions: the first
  8401.       # `new-line tab" not preceded by backslash (continuation
  8402.       # line).
  8403.       my $paragraph = $_;
  8404.       /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
  8405.       my ($relationship, $actions) = ($1, $2 || '');
  8406.  
  8407.       # Separate targets from dependencies: the first colon.
  8408.       $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
  8409.       my ($targets, $dependencies) = ($1, $2);
  8410.       # Remove the escaped new lines.
  8411.       # I don't know why, but I have to use a tmp $flat_deps.
  8412.       my $flat_deps = &flatten ($dependencies);
  8413.       my @deps = split (' ', $flat_deps);
  8414.  
  8415.       foreach (split (' ' , $targets))
  8416.         {
  8417.           # FIXME: 1. We are not robust to people defining several targets
  8418.           # at once, only some of them being in %dependencies.  The
  8419.           # actions from the targets in %dependencies are usually generated
  8420.           # from the content of %actions, but if some targets in $targets
  8421.           # are not in %dependencies the ELSE branch will output
  8422.           # a rule for all $targets (i.e. the targets which are both
  8423.           # in %dependencies and $targets will have two rules).
  8424.  
  8425.           # FIXME: 2. The logic here is not able to output a
  8426.           # multi-paragraph rule several time (e.g. for each conditional
  8427.           # it is defined for) because it only knows the first paragraph.
  8428.  
  8429.           # FIXME: 3. We are not robust to people defining a subset
  8430.           # of a previously defined "multiple-target" rule.  E.g.
  8431.           # `foo:' after `foo bar:'.
  8432.  
  8433.           # Output only if not in FALSE.
  8434.           if (defined $dependencies{$_} && $cond ne 'FALSE')
  8435.         {
  8436.           &depend ($_, @deps);
  8437.           if ($actions{$_})
  8438.             {
  8439.               $actions{$_} .= "\n$actions" if $actions;
  8440.             }
  8441.           else
  8442.             {
  8443.               $actions{$_} = $actions;
  8444.             }
  8445.         }
  8446.           else
  8447.         {
  8448.           # Free-lance dependency.  Output the rule for all the
  8449.           # targets instead of one by one.
  8450.           my @undefined_conds =
  8451.             rule_define ($targets, $file,
  8452.                  $is_am ? TARGET_AUTOMAKE : TARGET_USER,
  8453.                  $cond || 'TRUE', $file);
  8454.           for my $undefined_cond (@undefined_conds)
  8455.             {
  8456.               my $condparagraph = $paragraph;
  8457.               $condparagraph =~ s/^/$undefined_cond/gm;
  8458.               $result_rules .= "$spacing$comment$condparagraph\n";
  8459.             }
  8460.           if (scalar @undefined_conds == 0)
  8461.             {
  8462.               # Remember to discard next paragraphs
  8463.               # if they belong to this rule.
  8464.               # (but see also FIXME: #2 above.)
  8465.               $discard_rule = 1;
  8466.             }
  8467.           $comment = $spacing = '';
  8468.           last;
  8469.         }
  8470.         }
  8471.      }
  8472.  
  8473.      elsif (/$ASSIGNMENT_PATTERN/mso)
  8474.      {
  8475.         my ($var, $type, $val) = ($1, $2, $3);
  8476.          error $file, "variable `$var' with trailing backslash"
  8477.           if /\\$/;
  8478.  
  8479.         $is_rule = 0;
  8480.  
  8481.         # Accumulating variables must not be output.
  8482.         append_comments ($cond || 'TRUE', $var, $spacing, $comment);
  8483.         macro_define ($var, $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
  8484.               $type, $cond, $val, $file)
  8485.           if $cond ne 'FALSE';
  8486.         push (@var_list, $var);
  8487.  
  8488.         # If the user has set some variables we were in charge
  8489.         # of (which is detected by the first reading of
  8490.         # `header-vars.am'), we must not output them.
  8491.         $result_vars .= "$spacing$comment$_\n"
  8492.           if ($cond ne 'FALSE' && $type ne '+'
  8493.           && exists $var_owner{$var}{$cond || 'TRUE'}
  8494.           && $var_owner{$var}{$cond || 'TRUE'} == VAR_AUTOMAKE);
  8495.  
  8496.          $comment = $spacing = '';
  8497.      }
  8498.      else
  8499.      {
  8500.         # This isn't an error; it is probably some tokens which
  8501.         # configure is supposed to replace, such as `@SET-MAKE@',
  8502.         # or some part of a rule cut by an if/endif.
  8503.           if ($cond ne 'FALSE' && ! ($is_rule && $discard_rule))
  8504.           {
  8505.         s/^/make_condition (@cond_stack)/gme;
  8506.         $result_rules .= "$spacing$comment$_\n";
  8507.           }
  8508.          $comment = $spacing = '';
  8509.      }
  8510.     }
  8511.  
  8512.     err_am (@cond_stack ?
  8513.         "unterminated conditionals: @cond_stack" :
  8514.         "too many conditionals closed in include file")
  8515.       if "@saved_cond_stack" ne "@cond_stack";
  8516.  
  8517.     return ($comment, $result_vars, $result_rules);
  8518. }
  8519.  
  8520.  
  8521. # $CONTENTS
  8522. # &file_contents ($BASENAME, [%TRANSFORM])
  8523. # ----------------------------------------
  8524. # Return contents of a file from $libdir/am, automatically skipping
  8525. # macros or rules which are already known.
  8526. sub file_contents ($%)
  8527. {
  8528.     my ($basename, %transform) = @_;
  8529.     my ($comments, $variables, $rules) =
  8530.       file_contents_internal (1, "$libdir/am/$basename.am", %transform);
  8531.     return "$comments$variables$rules";
  8532. }
  8533.  
  8534.  
  8535. # $REGEXP
  8536. # &transform (%PAIRS)
  8537. # -------------------
  8538. # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
  8539. # for file_contents which:
  8540. #   - replaces %$TOKEN% with $VAL,
  8541. #   - enables/disables ?$TOKEN? and ?!$TOKEN?,
  8542. #   - replaces %?$TOKEN% with TRUE or FALSE.
  8543. sub transform (%)
  8544. {
  8545.     my (%pairs) = @_;
  8546.     my $result = '';
  8547.  
  8548.     while (my ($token, $val) = each %pairs)
  8549.     {
  8550.         $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
  8551.     if ($val)
  8552.     {
  8553.         $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
  8554.         $result .= "s/\Q%?$token%\E/TRUE/gm;";
  8555.     }
  8556.     else
  8557.     {
  8558.         $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
  8559.         $result .= "s/\Q%?$token%\E/FALSE/gm;";
  8560.     }
  8561.     }
  8562.  
  8563.     return $result;
  8564. }
  8565.  
  8566.  
  8567. # &append_exeext ($MACRO)
  8568. # -----------------------
  8569. # Macro is an Automake magic macro which primary is PROGRAMS, e.g.
  8570. # bin_PROGRAMS.  Make sure these programs have $(EXEEXT) appended.
  8571. sub append_exeext ($)
  8572. {
  8573.   my ($macro) = @_;
  8574.  
  8575.   prog_error "append_exeext ($macro)"
  8576.     unless $macro =~ /_PROGRAMS$/;
  8577.  
  8578.   my @conds = variable_conditions_recursive ($macro);
  8579.  
  8580.   my @condvals;
  8581.   foreach my $cond (@conds)
  8582.     {
  8583.       my @one_binlist = ();
  8584.       my @condval = variable_value_as_list_recursive ($macro, $cond);
  8585.       foreach my $rcurs (@condval)
  8586.     {
  8587.       # Skip autoconf substs.  Also skip if the user
  8588.       # already applied $(EXEEXT).
  8589.       if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
  8590.         {
  8591.           push (@one_binlist, $rcurs);
  8592.         }
  8593.       else
  8594.         {
  8595.           push (@one_binlist, $rcurs . '$(EXEEXT)');
  8596.         }
  8597.     }
  8598.  
  8599.       push (@condvals, $cond);
  8600.       push (@condvals, "@one_binlist");
  8601.     }
  8602.  
  8603.   macro_delete ($macro);
  8604.   while (@condvals)
  8605.     {
  8606.       my $cond = shift (@condvals);
  8607.       my @val = split (' ', shift (@condvals));
  8608.       define_pretty_variable ($macro, $cond, @val);
  8609.     }
  8610.  }
  8611.  
  8612.  
  8613. # @PREFIX
  8614. # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
  8615. # -----------------------------------------------------
  8616. # Find all variable prefixes that are used for install directories.  A
  8617. # prefix `zar' qualifies iff:
  8618. #
  8619. # * `zardir' is a variable.
  8620. # * `zar_PRIMARY' is a variable.
  8621. #
  8622. # As a side effect, it looks for misspellings.  It is an error to have
  8623. # a variable ending in a "reserved" suffix whose prefix is unknown, eg
  8624. # "bni_PROGRAMS".  However, unusual prefixes are allowed if a variable
  8625. # of the same name (with "dir" appended) exists.  For instance, if the
  8626. # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
  8627. # This is to provide a little extra flexibility in those cases which
  8628. # need it.
  8629. sub am_primary_prefixes ($$@)
  8630. {
  8631.   my ($primary, $can_dist, @prefixes) = @_;
  8632.  
  8633.   local $_;
  8634.   my %valid = map { $_ => 0 } @prefixes;
  8635.   $valid{'EXTRA'} = 0;
  8636.   foreach my $varname (keys %var_value)
  8637.     {
  8638.       # Automake is allowed to define variables that look like primaries
  8639.       # but which aren't.  E.g. INSTALL_sh_DATA.
  8640.       # Autoconf can also define variables like INSTALL_DATA, so
  8641.       # ignore all configure variables (at least those which are not
  8642.       # redefined in Makefile.am).
  8643.       # FIXME: We should make sure that these variables are not
  8644.       # conditionally defined (or else adjust the condition below).
  8645.       next
  8646.     if (exists $var_owner{$varname}
  8647.         && exists $var_owner{$varname}{'TRUE'}
  8648.         && $var_owner{$varname}{'TRUE'} != VAR_MAKEFILE);
  8649.  
  8650.       if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
  8651.     {
  8652.       my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
  8653.       if ($dist ne '' && ! $can_dist)
  8654.             {
  8655.           err_var ($varname,
  8656.                "invalid variable `$varname': `dist' is forbidden");
  8657.         }
  8658.       # Standard directories must be explicitly allowed.
  8659.       elsif (! defined $valid{$X} && exists $standard_prefix{$X})
  8660.         {
  8661.           err_var ($varname,
  8662.                "`${X}dir' is not a legitimate directory " .
  8663.                "for `$primary'");
  8664.         }
  8665.       # A not explicitly valid directory is allowed if Xdir is defined.
  8666.       elsif (! defined $valid{$X} &&
  8667.          require_variables_for_macro ($varname, "`$varname' is used",
  8668.                           "${X}dir"))
  8669.         {
  8670.           # Nothing to do.  Any error message has been output
  8671.           # by require_variables_for_macro.
  8672.         }
  8673.       else
  8674.         {
  8675.           # Ensure all extended prefixes are actually used.
  8676.           $valid{"$base$dist$X"} = 1;
  8677.         }
  8678.     }
  8679.     }
  8680.  
  8681.   # Return only those which are actually defined.
  8682.   return sort grep { variable_defined ($_ . '_' . $primary) } keys %valid;
  8683. }
  8684.  
  8685.  
  8686. # Handle `where_HOW' variable magic.  Does all lookups, generates
  8687. # install code, and possibly generates code to define the primary
  8688. # variable.  The first argument is the name of the .am file to munge,
  8689. # the second argument is the primary variable (eg HEADERS), and all
  8690. # subsequent arguments are possible installation locations.  Returns
  8691. # list of all values of all _HOW targets.
  8692. #
  8693. # FIXME: this should be rewritten to be cleaner.  It should be broken
  8694. # up into multiple functions.
  8695. #
  8696. # Usage is: am_install_var (OPTION..., file, HOW, where...)
  8697. sub am_install_var
  8698. {
  8699.     my (@args) = @_;
  8700.  
  8701.     my $do_require = 1;
  8702.     my $can_dist = 0;
  8703.     my $default_dist = 0;
  8704.     while (@args)
  8705.     {
  8706.     if ($args[0] eq '-noextra')
  8707.     {
  8708.         $do_require = 0;
  8709.     }
  8710.     elsif ($args[0] eq '-candist')
  8711.     {
  8712.         $can_dist = 1;
  8713.     }
  8714.     elsif ($args[0] eq '-defaultdist')
  8715.     {
  8716.         $default_dist = 1;
  8717.         $can_dist = 1;
  8718.     }
  8719.     elsif ($args[0] !~ /^-/)
  8720.     {
  8721.         last;
  8722.     }
  8723.     shift (@args);
  8724.     }
  8725.  
  8726.     my ($file, $primary, @prefix) = @args;
  8727.  
  8728.     # Now that configure substitutions are allowed in where_HOW
  8729.     # variables, it is an error to actually define the primary.  We
  8730.     # allow `JAVA', as it is customarily used to mean the Java
  8731.     # interpreter.  This is but one of several Java hacks.  Similarly,
  8732.     # `PYTHON' is customarily used to mean the Python interpreter.
  8733.     reject_var $primary, "`$primary' is an anachronism"
  8734.       unless $primary eq 'JAVA' || $primary eq 'PYTHON';
  8735.  
  8736.     # Get the prefixes which are valid and actually used.
  8737.     @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
  8738.  
  8739.     # If a primary includes a configure substitution, then the EXTRA_
  8740.     # form is required.  Otherwise we can't properly do our job.
  8741.     my $require_extra;
  8742.  
  8743.     my @used = ();
  8744.     my @result = ();
  8745.  
  8746.     # True if the iteration is the first one.  Used for instance to
  8747.     # output parts of the associated file only once.
  8748.     my $first = 1;
  8749.     foreach my $X (@prefix)
  8750.     {
  8751.     my $nodir_name = $X;
  8752.     my $one_name = $X . '_' . $primary;
  8753.  
  8754.     my $strip_subdir = 1;
  8755.     # If subdir prefix should be preserved, do so.
  8756.     if ($nodir_name =~ /^nobase_/)
  8757.       {
  8758.         $strip_subdir = 0;
  8759.         $nodir_name =~ s/^nobase_//;
  8760.       }
  8761.  
  8762.     # If files should be distributed, do so.
  8763.     my $dist_p = 0;
  8764.     if ($can_dist)
  8765.       {
  8766.         $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
  8767.                || (! $default_dist && $nodir_name =~ /^dist_/));
  8768.         $nodir_name =~ s/^(dist|nodist)_//;
  8769.       }
  8770.  
  8771.     # Append actual contents of where_PRIMARY variable to
  8772.     # result.
  8773.     foreach my $rcurs (&variable_value_as_list_recursive ($one_name, 'all'))
  8774.       {
  8775.         # Skip configure substitutions.  Possibly bogus.
  8776.         if ($rcurs =~ /^\@.*\@$/)
  8777.           {
  8778.         if ($nodir_name eq 'EXTRA')
  8779.           {
  8780.             err_var ($one_name,
  8781.                  "`$one_name' contains configure substitution, "
  8782.                  . "but shouldn't");
  8783.           }
  8784.         # Check here to make sure variables defined in
  8785.         # configure.ac do not imply that EXTRA_PRIMARY
  8786.         # must be defined.
  8787.         elsif (! defined $configure_vars{$one_name})
  8788.           {
  8789.             $require_extra = $one_name
  8790.               if $do_require;
  8791.           }
  8792.  
  8793.         next;
  8794.           }
  8795.  
  8796.         push (@result, $rcurs);
  8797.       }
  8798.     # A blatant hack: we rewrite each _PROGRAMS primary to include
  8799.     # EXEEXT.
  8800.     append_exeext ($one_name)
  8801.       if $primary eq 'PROGRAMS';
  8802.     # "EXTRA" shouldn't be used when generating clean targets,
  8803.     # all, or install targets.  We used to warn if EXTRA_FOO was
  8804.     # defined uselessly, but this was annoying.
  8805.     next
  8806.       if $nodir_name eq 'EXTRA';
  8807.  
  8808.     if ($nodir_name eq 'check')
  8809.       {
  8810.         push (@check, '$(' . $one_name . ')');
  8811.       }
  8812.     else
  8813.       {
  8814.         push (@used, '$(' . $one_name . ')');
  8815.       }
  8816.  
  8817.     # Is this to be installed?
  8818.     my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
  8819.  
  8820.     # If so, with install-exec? (or install-data?).
  8821.     my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
  8822.  
  8823.     my $check_options_p = $install_p
  8824.                   && defined $options{'std-options'};
  8825.  
  8826.     # Singular form of $PRIMARY.
  8827.     (my $one_primary = $primary) =~ s/S$//;
  8828.     $output_rules .= &file_contents ($file,
  8829.                      ('FIRST' => $first,
  8830.  
  8831.                       'PRIMARY'     => $primary,
  8832.                       'ONE_PRIMARY' => $one_primary,
  8833.                       'DIR'         => $X,
  8834.                       'NDIR'        => $nodir_name,
  8835.                       'BASE'        => $strip_subdir,
  8836.  
  8837.                       'EXEC'    => $exec_p,
  8838.                       'INSTALL' => $install_p,
  8839.                       'DIST'    => $dist_p,
  8840.                       'CK-OPTS' => $check_options_p));
  8841.  
  8842.     $first = 0;
  8843.     }
  8844.  
  8845.     # The JAVA variable is used as the name of the Java interpreter.
  8846.     # The PYTHON variable is used as the name of the Python interpreter.
  8847.     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
  8848.     {
  8849.     # Define it.
  8850.     define_pretty_variable ($primary, '', @used);
  8851.     $output_vars .= "\n";
  8852.     }
  8853.  
  8854.     err_var ($require_extra,
  8855.          "`$require_extra' contains configure substitution,\n"
  8856.          . "but `EXTRA_$primary' not defined")
  8857.       if ($require_extra && ! variable_defined ('EXTRA_' . $primary));
  8858.  
  8859.     # Push here because PRIMARY might be configure time determined.
  8860.     push (@all, '$(' . $primary . ')')
  8861.     if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
  8862.  
  8863.     # Make the result unique.  This lets the user use conditionals in
  8864.     # a natural way, but still lets us program lazily -- we don't have
  8865.     # to worry about handling a particular object more than once.
  8866.     return uniq (sort @result);
  8867. }
  8868.  
  8869.  
  8870. ################################################################
  8871.  
  8872. # Each key in this hash is the name of a directory holding a
  8873. # Makefile.in.  These variables are local to `is_make_dir'.
  8874. my %make_dirs = ();
  8875. my $make_dirs_set = 0;
  8876.  
  8877. sub is_make_dir
  8878. {
  8879.     my ($dir) = @_;
  8880.     if (! $make_dirs_set)
  8881.     {
  8882.     foreach my $iter (@configure_input_files)
  8883.     {
  8884.         $make_dirs{dirname ($iter)} = 1;
  8885.     }
  8886.     # We also want to notice Makefile.in's.
  8887.     foreach my $iter (@other_input_files)
  8888.     {
  8889.         if ($iter =~ /Makefile\.in$/)
  8890.         {
  8891.         $make_dirs{dirname ($iter)} = 1;
  8892.         }
  8893.     }
  8894.     $make_dirs_set = 1;
  8895.     }
  8896.     return defined $make_dirs{$dir};
  8897. }
  8898.  
  8899. ################################################################
  8900.  
  8901. # This variable is local to the "require file" set of functions.
  8902. my @require_file_paths = ();
  8903.  
  8904.  
  8905. # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
  8906. # --------------------------------------------------
  8907. # See if we want to push this file onto dist_common.  This function
  8908. # encodes the rules for deciding when to do so.
  8909. sub maybe_push_required_file
  8910. {
  8911.     my ($dir, $file, $fullfile) = @_;
  8912.  
  8913.     if ($dir eq $relative_dir)
  8914.     {
  8915.     push_dist_common ($file);
  8916.     return 1;
  8917.     }
  8918.     elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
  8919.     {
  8920.     # If we are doing the topmost directory, and the file is in a
  8921.     # subdir which does not have a Makefile, then we distribute it
  8922.     # here.
  8923.     push_dist_common ($fullfile);
  8924.     return 1;
  8925.     }
  8926.     return 0;
  8927. }
  8928.  
  8929.  
  8930. # &require_file_internal ($WHERE, $MYSTRICT, @FILES)
  8931. # --------------------------------------------------
  8932. # Verify that the file must exist in the current directory.
  8933. # $MYSTRICT is the strictness level at which this file becomes required.
  8934. #
  8935. # Must set require_file_paths before calling this function.
  8936. # require_file_paths is set to hold a single directory (the one in
  8937. # which the first file was found) before return.
  8938. sub require_file_internal ($$@)
  8939. {
  8940.     my ($where, $mystrict, @files) = @_;
  8941.  
  8942.     foreach my $file (@files)
  8943.     {
  8944.         my $fullfile;
  8945.     my $errdir;
  8946.     my $errfile;
  8947.     my $save_dir;
  8948.  
  8949.     my $found_it = 0;
  8950.     my $dangling_sym = 0;
  8951.     foreach my $dir (@require_file_paths)
  8952.     {
  8953.         $fullfile = $dir . "/" . $file;
  8954.         $errdir = $dir unless $errdir;
  8955.  
  8956.         # Use different name for "error filename".  Otherwise on
  8957.         # an error the bad file will be reported as eg
  8958.         # `../../install-sh' when using the default
  8959.         # config_aux_path.
  8960.         $errfile = $errdir . '/' . $file;
  8961.  
  8962.         if (-l $fullfile && ! -f $fullfile)
  8963.         {
  8964.         $dangling_sym = 1;
  8965.         last;
  8966.         }
  8967.         elsif (-f $fullfile)
  8968.         {
  8969.         $found_it = 1;
  8970.         maybe_push_required_file ($dir, $file, $fullfile);
  8971.         $save_dir = $dir;
  8972.         last;
  8973.         }
  8974.     }
  8975.  
  8976.     # `--force-missing' only has an effect if `--add-missing' is
  8977.     # specified.
  8978.     if ($found_it && (! $add_missing || ! $force_missing))
  8979.     {
  8980.         # Prune the path list.
  8981.         @require_file_paths = $save_dir;
  8982.     }
  8983.     else
  8984.     {
  8985.         # If we've already looked for it, we're done.  You might
  8986.         # wonder why we don't do this before searching for the
  8987.         # file.  If we do that, then something like
  8988.         # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
  8989.         # DIST_COMMON.
  8990.         if (! $found_it)
  8991.         {
  8992.         next if defined $require_file_found{$fullfile};
  8993.         $require_file_found{$fullfile} = 1;
  8994.         }
  8995.  
  8996.         if ($strictness >= $mystrict)
  8997.         {
  8998.         if ($dangling_sym && $add_missing)
  8999.         {
  9000.             unlink ($fullfile);
  9001.         }
  9002.  
  9003.         my $trailer = '';
  9004.         my $suppress = 0;
  9005.  
  9006.         # Only install missing files according to our desired
  9007.         # strictness level.
  9008.         my $message = "required file `$errfile' not found";
  9009.         if ($add_missing)
  9010.         {
  9011.             if (-f ("$libdir/$file"))
  9012.             {
  9013.                 $suppress = 1;
  9014.  
  9015.             # Install the missing file.  Symlink if we
  9016.             # can, copy if we must.  Note: delete the file
  9017.             # first, in case it is a dangling symlink.
  9018.             $message = "installing `$errfile'";
  9019.             # Windows Perl will hang if we try to delete a
  9020.             # file that doesn't exist.
  9021.             unlink ($errfile) if -f $errfile;
  9022.             if ($symlink_exists && ! $copy_missing)
  9023.             {
  9024.                 if (! symlink ("$libdir/$file", $errfile))
  9025.                 {
  9026.                 $suppress = 0;
  9027.                 $trailer = "; error while making link: $!";
  9028.                 }
  9029.             }
  9030.             elsif (system ('cp', "$libdir/$file", $errfile))
  9031.             {
  9032.                 $suppress = 0;
  9033.                 $trailer = "\n    error while copying";
  9034.             }
  9035.             }
  9036.  
  9037.             if (! maybe_push_required_file (dirname ($errfile),
  9038.                                                     $file, $errfile))
  9039.             {
  9040.             if (! $found_it)
  9041.             {
  9042.                 # We have added the file but could not push it
  9043.                 # into DIST_COMMON (probably because this is
  9044.                 # an auxiliary file and we are not processing
  9045.                 # the top level Makefile). This is unfortunate,
  9046.                 # since it means we are using a file which is not
  9047.                 # distributed!
  9048.  
  9049.                 # Get Automake to be run again: on the second
  9050.                 # run the file will be found, and pushed into
  9051.                 # the toplevel DIST_COMMON automatically.
  9052.                 $automake_needs_to_reprocess_all_files = 1;
  9053.             }
  9054.             }
  9055.  
  9056.             # Prune the path list.
  9057.             @require_file_paths = &dirname ($errfile);
  9058.         }
  9059.  
  9060.         # If --force-missing was specified, and we have
  9061.         # actually found the file, then do nothing.
  9062.         next
  9063.             if $found_it && $force_missing;
  9064.  
  9065.         # If we couldn' install the file, but it is a target in
  9066.         # the Makefile, don't print anything.  This allows files
  9067.         # like README, AUTHORS, or THANKS to be generated.
  9068.         next
  9069.           if !$suppress && target_defined ($file);
  9070.  
  9071.         msg ($suppress ? 'note' : 'error', $where, "$message$trailer");
  9072.         }
  9073.     }
  9074.     }
  9075. }
  9076.  
  9077. # &require_file ($WHERE, $MYSTRICT, @FILES)
  9078. # -----------------------------------------
  9079. sub require_file ($$@)
  9080. {
  9081.     my ($where, $mystrict, @files) = @_;
  9082.     @require_file_paths = $relative_dir;
  9083.     require_file_internal ($where, $mystrict, @files);
  9084. }
  9085.  
  9086. # &require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
  9087. # -----------------------------------------------------------
  9088. sub require_file_with_macro ($$$@)
  9089. {
  9090.     my ($cond, $macro, $mystrict, @files) = @_;
  9091.     require_file ($var_location{$macro}{$cond}, $mystrict, @files);
  9092. }
  9093.  
  9094.  
  9095. # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
  9096. # ----------------------------------------------
  9097. # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
  9098. sub require_conf_file ($$@)
  9099. {
  9100.     my ($where, $mystrict, @files) = @_;
  9101.     @require_file_paths = @config_aux_path;
  9102.     require_file_internal ($where, $mystrict, @files);
  9103.     my $dir = $require_file_paths[0];
  9104.     @config_aux_path = @require_file_paths;
  9105.      # Avoid unsightly '/.'s.
  9106.     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
  9107. }
  9108.  
  9109.  
  9110. # &require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
  9111. # ----------------------------------------------------------------
  9112. sub require_conf_file_with_macro ($$$@)
  9113. {
  9114.     my ($cond, $macro, $mystrict, @files) = @_;
  9115.     require_conf_file ($var_location{$macro}{$cond}, $mystrict, @files);
  9116. }
  9117.  
  9118. ################################################################
  9119.  
  9120. # &require_build_directory ($DIRECTORY)
  9121. # ------------------------------------
  9122. # Emit rules to create $DIRECTORY if needed, and return
  9123. # the file that any target requiring this directory should be made
  9124. # dependent upon.
  9125. sub require_build_directory ($)
  9126. {
  9127.   my $directory = shift;
  9128.   my $dirstamp = "$directory/\$(am__dirstamp)";
  9129.  
  9130.   # Don't emit the rule twice.
  9131.   if (! defined $directory_map{$directory})
  9132.     {
  9133.       $directory_map{$directory} = 1;
  9134.  
  9135.       # Set a variable for the dirstamp basename.
  9136.       define_pretty_variable ('am__dirstamp', 'TRUE',
  9137.                   '$(am__leading_dot)dirstamp')
  9138.     unless variable_defined ('am__dirstamp');
  9139.  
  9140.       # Directory must be removed by `make distclean'.
  9141.       $clean_files{$dirstamp} = DIST_CLEAN;
  9142.  
  9143.       $output_rules .= ("$dirstamp:\n"
  9144.             . "\t\@\$(mkinstalldirs) $directory\n"
  9145.             . "\t\@: > $dirstamp\n");
  9146.     }
  9147.  
  9148.   return $dirstamp;
  9149. }
  9150.  
  9151. # &require_build_directory_maybe ($FILE)
  9152. # --------------------------------------
  9153. # If $FILE lies in a subdirectory, emit a rule to create this
  9154. # directory and return the file that $FILE should be made
  9155. # dependent upon.  Otherwise, just return the empty string.
  9156. sub require_build_directory_maybe ($)
  9157. {
  9158.     my $file = shift;
  9159.     my $directory = dirname ($file);
  9160.  
  9161.     if ($directory ne '.')
  9162.     {
  9163.     return require_build_directory ($directory);
  9164.     }
  9165.     else
  9166.     {
  9167.     return '';
  9168.     }
  9169. }
  9170.  
  9171. ################################################################
  9172.  
  9173. # Push a list of files onto dist_common.
  9174. sub push_dist_common
  9175. {
  9176.   prog_error "push_dist_common run after handle_dist"
  9177.     if $handle_dist_run;
  9178.   macro_define ('DIST_COMMON', VAR_AUTOMAKE, '+', '', "@_", '');
  9179. }
  9180.  
  9181.  
  9182. # Set strictness.
  9183. sub set_strictness
  9184. {
  9185.   $strictness_name = $_[0];
  9186.  
  9187.   # FIXME: 'portability' warnings are currently disabled by default.
  9188.   # Eventually we want to turn them on in GNU and GNITS modes, but
  9189.   # we don't do this yet in Automake 1.7 to help the 1.6/1.7 transition.
  9190.   #
  9191.   # Indeed there would be only two ways to get rid of these new warnings:
  9192.   #  1. adjusting Makefile.am
  9193.   #     This is not always easy (or wanted).  Consider %-rules or
  9194.   #     $(function args) variables.
  9195.   #  2. using -Wno-portability
  9196.   #     This means there is no way to have the same Makefile.am
  9197.   #     working both with Automake 1.6 and 1.7 (since 1.6 does not
  9198.   #     understand -Wno-portability).
  9199.   #
  9200.   # In Automake 1.8 (or whatever it is called) we can turn these
  9201.   # warnings on, since -Wno-portability will not be an issue for
  9202.   # the 1.7/1.8 transition.
  9203.   if ($strictness_name eq 'gnu')
  9204.     {
  9205.       $strictness = GNU;
  9206.       setup_channel 'error-gnu', silent => 0;
  9207.       setup_channel 'error-gnu/warn', silent => 0, type => 'error';
  9208.       setup_channel 'error-gnits', silent => 1;
  9209.       # setup_channel 'portability', silent => 0;
  9210.       setup_channel 'gnu', silent => 0;
  9211.     }
  9212.   elsif ($strictness_name eq 'gnits')
  9213.     {
  9214.       $strictness = GNITS;
  9215.       setup_channel 'error-gnu', silent => 0;
  9216.       setup_channel 'error-gnu/warn', silent => 0, type => 'error';
  9217.       setup_channel 'error-gnits', silent => 0;
  9218.       # setup_channel 'portability', silent => 0;
  9219.       setup_channel 'gnu', silent => 0;
  9220.     }
  9221.   elsif ($strictness_name eq 'foreign')
  9222.     {
  9223.       $strictness = FOREIGN;
  9224.       setup_channel 'error-gnu', silent => 1;
  9225.       setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
  9226.       setup_channel 'error-gnits', silent => 1;
  9227.       # setup_channel 'portability', silent => 1;
  9228.       setup_channel 'gnu', silent => 1;
  9229.     }
  9230.   else
  9231.     {
  9232.       prog_error "level `$strictness_name' not recognized\n";
  9233.     }
  9234. }
  9235.  
  9236.  
  9237. ################################################################
  9238.  
  9239. # Glob something.  Do this to avoid indentation screwups everywhere we
  9240. # want to glob.  Gross!
  9241. sub my_glob
  9242. {
  9243.     my ($pat) = @_;
  9244.     return <${pat}>;
  9245. }
  9246.  
  9247. ################################################################
  9248.  
  9249. # INTEGER
  9250. # require_variables ($WHERE, $REASON, $COND, @VARIABLES)
  9251. # ------------------------------------------------------
  9252. # Make sure that each supplied variable is defined in $COND.
  9253. # Otherwise, issue a warning.  If we know which macro can
  9254. # define this variable, hint the user.
  9255. # Return the number of undefined variables.
  9256. sub require_variables ($$$@)
  9257. {
  9258.   my ($where, $reason, $cond, @vars) = @_;
  9259.   my $res = 0;
  9260.   $reason .= ' but ' unless $reason eq '';
  9261.  
  9262.  VARIABLE:
  9263.   foreach my $var (@vars)
  9264.     {
  9265.       # Nothing to do if the variable exists.  The $configure_vars test
  9266.       # needed for strange variables like AMDEPBACKSLASH or ANSI2KNR
  9267.       # that are AC_SUBST'ed but never macro_define'd.
  9268.       next VARIABLE
  9269.     if ((exists $var_value{$var} && exists $var_value{$var}{$cond})
  9270.         || exists $configure_vars{$var});
  9271.  
  9272.       my @undef_cond = variable_not_always_defined_in_cond $var, $cond;
  9273.       next VARIABLE
  9274.     unless @undef_cond;
  9275.  
  9276.       my $text = "$reason`$var' is undefined\n";
  9277.       if (@undef_cond && $undef_cond[0] ne 'TRUE')
  9278.     {
  9279.       $text .= ("in the following conditions:\n  "
  9280.             . join ("\n  ", @undef_cond));
  9281.     }
  9282.  
  9283.       ++$res;
  9284.  
  9285.       if (exists $am_macro_for_var{$var})
  9286.     {
  9287.       $text .= "\nThe usual way to define `$var' is to add "
  9288.         . "`$am_macro_for_var{$var}'\nto `$configure_ac' and run "
  9289.         . "`aclocal' and `autoconf' again.";
  9290.     }
  9291.       elsif (exists $ac_macro_for_var{$var})
  9292.     {
  9293.       $text .= "\nThe usual way to define `$var' is to add "
  9294.         . "`$ac_macro_for_var{$var}'\nto `$configure_ac' and run "
  9295.         . "`autoconf' again.";
  9296.     }
  9297.  
  9298.       error $where, $text, uniq_scope => US_GLOBAL;
  9299.     }
  9300.   return $res;
  9301. }
  9302.  
  9303. # INTEGER
  9304. # require_variables_for_macro ($MACRO, $REASON, @VARIABLES)
  9305. # ---------------------------------------------------------
  9306. # Same as require_variables, but take a macro mame as first argument.
  9307. sub require_variables_for_macro ($$@)
  9308. {
  9309.   my ($macro, $reason, @args) = @_;
  9310.   for my $cond (keys %{$var_value{$macro}})
  9311.     {
  9312.       return require_variables ($var_location{$macro}{$cond}, $reason,
  9313.                 $cond, @args);
  9314.     }
  9315. }
  9316.  
  9317. # Print usage information.
  9318. sub usage ()
  9319. {
  9320.     print "Usage: $0 [OPTION] ... [Makefile]...
  9321.  
  9322. Generate Makefile.in for configure from Makefile.am.
  9323.  
  9324. Operation modes:
  9325.       --help               print this help, then exit
  9326.       --version            print version number, then exit
  9327.   -v, --verbose            verbosely list files processed
  9328.       --no-force           only update Makefile.in's that are out of date
  9329.   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY
  9330.  
  9331. Dependency tracking:
  9332.   -i, --ignore-deps      disable dependency tracking code
  9333.       --include-deps     enable dependency tracking code
  9334.  
  9335. Flavors:
  9336.       --cygnus           assume program is part of Cygnus-style tree
  9337.       --foreign          set strictness to foreign
  9338.       --gnits            set strictness to gnits
  9339.       --gnu              set strictness to gnu
  9340.  
  9341. Library files:
  9342.   -a, --add-missing      add missing standard files to package
  9343.       --libdir=DIR       directory storing library files
  9344.   -c, --copy             with -a, copy missing files (default is symlink)
  9345.   -f, --force-missing    force update of standard files
  9346.  
  9347. Warning categories include:
  9348.   `gnu'           GNU coding standards (default in gnu and gnits modes)
  9349.   `obsolete'      obsolete features or constructions
  9350.   `portability'   portability issues
  9351.   `syntax'        dubious syntactic constructs (default)
  9352.   `unsupported'   unsupported or incomplete features (default)
  9353.   `all'           all the warnings
  9354.   `no-CATEGORY'   turn off warnings in CATEGORY
  9355.   `none'          turn off all the warnings
  9356.   `error'         treat warnings as errors
  9357. ";
  9358.  
  9359.     my ($last, @lcomm);
  9360.     $last = '';
  9361.     foreach my $iter (sort ((@common_files, @common_sometimes)))
  9362.     {
  9363.     push (@lcomm, $iter) unless $iter eq $last;
  9364.     $last = $iter;
  9365.     }
  9366.  
  9367.     my @four;
  9368.     print "\nFiles which are automatically distributed, if found:\n";
  9369.     format USAGE_FORMAT =
  9370.   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
  9371.   $four[0],           $four[1],           $four[2],           $four[3]
  9372. .
  9373.     $~ = "USAGE_FORMAT";
  9374.  
  9375.     my $cols = 4;
  9376.     my $rows = int(@lcomm / $cols);
  9377.     my $rest = @lcomm % $cols;
  9378.  
  9379.     if ($rest)
  9380.     {
  9381.     $rows++;
  9382.     }
  9383.     else
  9384.     {
  9385.     $rest = $cols;
  9386.     }
  9387.  
  9388.     for (my $y = 0; $y < $rows; $y++)
  9389.     {
  9390.     @four = ("", "", "", "");
  9391.     for (my $x = 0; $x < $cols; $x++)
  9392.     {
  9393.         last if $y + 1 == $rows && $x == $rest;
  9394.  
  9395.         my $idx = (($x > $rest)
  9396.                ?  ($rows * $rest + ($rows - 1) * ($x - $rest))
  9397.                : ($rows * $x));
  9398.  
  9399.         $idx += $y;
  9400.         $four[$x] = $lcomm[$idx];
  9401.     }
  9402.     write;
  9403.     }
  9404.  
  9405.     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
  9406.  
  9407.     # --help always returns 0 per GNU standards.
  9408.     exit 0;
  9409. }
  9410.  
  9411.  
  9412. # &version ()
  9413. # -----------
  9414. # Print version information
  9415. sub version ()
  9416. {
  9417.   print <<EOF;
  9418. automake (GNU $PACKAGE) $VERSION
  9419. Written by Tom Tromey <tromey\@redhat.com>.
  9420.  
  9421. Copyright 2003 Free Software Foundation, Inc.
  9422. This is free software; see the source for copying conditions.  There is NO
  9423. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9424. EOF
  9425.   # --version always returns 0 per GNU standards.
  9426.   exit 0;
  9427. }
  9428.  
  9429. ### Setup "GNU" style for perl-mode and cperl-mode.
  9430. ## Local Variables:
  9431. ## perl-indent-level: 2
  9432. ## perl-continued-statement-offset: 2
  9433. ## perl-continued-brace-offset: 0
  9434. ## perl-brace-offset: 0
  9435. ## perl-brace-imaginary-offset: 0
  9436. ## perl-label-offset: -2
  9437. ## cperl-indent-level: 2
  9438. ## cperl-brace-offset: 0
  9439. ## cperl-continued-brace-offset: 0
  9440. ## cperl-label-offset: -2
  9441. ## cperl-extra-newline-before-brace: t
  9442. ## cperl-merge-trailing-else: nil
  9443. ## cperl-continued-statement-offset: 2
  9444. ## End:
  9445.